![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@paybase/pool
Advanced tools
async/await
pooling mechanism built on top of Communicating Sequential Processes.
$ npm install --save @paybase/pool
or
$ yarn add @paybase/pool
Pooling can simplify many complex problems, for example:
By defining a process as something which is akin to a mutex lock, we can limit request parallelisation to the size of the pool.
const assert = require('assert');
const fetch = require('node-fetch');
const createPool = require('@paybase/pool');
const { run, close } = createPool({
poolSize: 2,
createProcess: () => Symbol('ticket'),
handler: (_, query) => {
console.log(`🚀 running request with query: ${query}`);
return fetch(`https://postman-echo.com/get?q=${query}`)
.then(res => res.json())
.then(res => assert.equal(res.args.q, query));
.then(_ => console.log(`👌 request completed successfully`));
}
});
(async () => {
const queries = Array.from({ length: 20 }, (_, i) => run(`${++i}`));
await Promise.all(queries);
close();
})();
For spawning multiple child processes and spreading usage between the pool.
const assert = require('assert');
const { spawn } = require('child_process');
const createPool = require('@paybase/pool');
const { run, close } = createPool({
poolSize: 10,
createProcess: () => {
const p = spawn('cat', [ '-' ]);
p.stdin.setEncoding('utf-8');
p.stdout.setEncoding('utf-8');
return p;
},
handler: (p, input) =>
new Promise(resolve => {
p.stdout.once('data', d => {
assert(d, input);
console.log(`👌 received data: ${d.trim()} from pid: ${p.pid}`);
resolve(d);
});
console.log(`🚀 sending data: ${input.trim()} to pid: ${p.pid}`);
p.stdin.write(input);
}),
});
(async () => {
const inputs = Array.from({ length: 100 }, (_, i) => run(`${++i}\n`));
await Promise.all(inputs);
close();
})();
This library exposes a single factory method for creating pools.
createPool({ poolSize = 5, createProcess, handler })
-> Pool
The pool factory takes an options object containing 3 properties:
poolSize
- defaults to 5, determines the size of the poolcreateProcess
- defines a process
factory function which can return anythinghandler(process, input)
-> Promise
- defines a function which handles a unit of work. The handler must return a Promise
and receives a process
(as defined by the process
factory) and the input
from a call to run
on the poolA returned Pool
exposes 2 methods:
Pool.run(input)
-> Promise
- The interface defined to run against the pool of processes, supplied input can be of any type as the handler supplied at pool
creation defines how the input interacts which the underlying processPool.close
-> Promise
- A mechanism for destroying the pool
when it is no longer neededContributions are welcomed and appreciated!
Feel free to get in touch if you have any questions.
Please see the LICENSE
file for more information.
FAQs
a pooling mechanism built on top of csp
The npm package @paybase/pool receives a total of 1 weekly downloads. As such, @paybase/pool popularity was classified as not popular.
We found that @paybase/pool demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.