Parallizer
Parallizer is a tool that makes working with asynchronous functions much easier.
Installation
$ npm install parallizer --save
Example
var Parallizer = // creates a new Parallizer object// that will only run 3 functions at the same time.var prl = 3 // very important: last argument must be the callback.var { } for var i = 0; i < 100; i++ var rnd = Math prl
Documentation
new Parallizer([max], [cb], [paused])
Creates an new Parallizer object.
Arguments
max
- The maximum concurrent running functions. (Default: 1)cb
- The callback that will be called if all functions have been executed.paused
- The queue is initially paused.
parallizer.sadd(fn[, arg1[, arg2[, ...]]])
Adds a function to the queue an executes it if possible.
Arguments
fn
- The function to be called, last argument must be a callback.arg1, arg2, ...
- Arguments forfn
.
parallizer.add(fn, [args], [cb], [scope], [high])
This function does the same like parallizer.sadd
, but with a different API.
Arguments
fn
- The function to be called, last argument must be a callback.args
- An array specifying the arguments with whichfn
should be called.cb
- Callback (last argument) offn
.scope
- The scope (this reference) in which thefn
is executed.high
- Iftrue
, pushesfn
in front of the queue.
parallizer.start()
Starts the paused queue.
parallizer.pause()
Pauses the queue.
Tests
$ npm install && npm test
Licence
Copyright © 2015 Christoph Witzko