0.2.3 • Published 5 years ago
xy-pool v0.2.3
Pool
Pool for JavaScript.
Installing
Using npm:
npm install xy-pool
Example
Implementing producer-consumer model.
const Pool = require('xy-pool');
const instance = new Pool({ maxSize: 10 });
// create a product
const product = producer();
// put the product into the pool
instance.push(product);
// get a product from the pool
consume(instance.pop());
Start async task with pool. It can limit the number of task.
const Pool = require('xy-pool');
const instance = new Pool({ maxSize: 10 });
instance.on('poolenter', onPoolEnter);
// start the task when the task enter the pool
function onPoolEnter(key, task) {
if (typeof task === 'function') {
task(key, task);
}
}
function post(key) {
http.post(...)
.then(...)
.catch(...)
.finally(function() { instance.pop(key) }); // remove the task when the async task is ok
}
// put the task into pool
instance.push(post);
0.2.3
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
1.0.0
5 years ago
0.1.14
5 years ago
0.1.13
5 years ago
0.1.12
5 years ago
0.1.11
5 years ago
0.1.10
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago