0.2.3 • Published 6 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
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
1.0.0
6 years ago
0.1.14
6 years ago
0.1.13
6 years ago
0.1.12
6 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.9
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago