0.0.4 • Published 8 years ago

moist v0.0.4

Weekly downloads
2
License
LicenseRef-LICENS...
Repository
github
Last release
8 years ago

moist

A small little resource pool

Installation

npm install moist --save

Instructions

// require modules
var Moist = require('moist');
var bluebird = require('bluebird');

// create new resource pool
var pool = new Moist({
  threads: 5
});

// "add" your functions to the queue. They can be synchronous or return a promise
pool.add(timeoutPromise).add(timeoutPromise).add(timeoutPromise).add(timeoutPromise).add(timeoutPromise).add(timeoutPromise);

pool.start({
        afterEachBatch: function(results){
            console.log('One batch of 5 has finished', results);
        }
    })
		.then(function(results) {
			  // results is an array of your results
		})
		.catch(function(errors) {
			  // console.error('ahhh!');
		})
		.done(function(){
		    // finished
		});

function timeoutPromise(){
    var defer = P.defer();
    setTimeout(function(){
        defer.resolve('data!');
    }, 100);
    return defer.promise;
}
0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago