1.1.0 • Published 8 years ago
uncomplicated-pool v1.1.0
pool
Simple pool for asynchronous tasks
uncomplicated-pool(size)
initialises a pool of the given size;
pool(x)
the passed function waits on the pool
pool()
call when something leaves the pool
Example
var pool = require('uncomplicated-pool');
var size = 8; // I'm on an eight core machine?
var actions = 200;
var my_pool, action;
// Define the pool
my_pool = pool(size);
function my_action(example, parameters, cb) {
// Some asynchronous action (e.g. running a c program)
cb();
}
while(actions--) {
// Ensure that the pool is left at the completion of an action
action = function() {
my_action("Example", "parameters", my_pool);
}
// Add the action to the pool
my_pool(action);
}