You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You must have component installed for browser usage and mocha, mocha-phantomjs installed for testing.
$ npm install -g component mocha mocha-phantomjs
$ git clone git@github.com:chemzqm/serial.git
$ cd serial && npm install
$ make
#run test on server side
$ make test#run test on phantomjs
$ make phantomjs
Example
functionsquare(n,done){setTimeout(function(){done(null,n*n);},100);}varSerial=require('serial');//The name is 'node-serial' in node environmentvarserial=newSerial();serial.timeout(1000);[1,2,3].forEach(function(){serial.add(function(done,ctx){square(1+(ctx.res||0),function(err,res){done(err,res);})})})serial.done(function(err,ctx){if(err)throwerr;// ctx.res => 25});
API
Serial()
Init new Serial instance.
.timeout(Number)
Set the timeout to number ms, default is 10s.
Note this timeout if for individual callback function.
.add(Function)
Add Function to serial, the first argument is a callback function, it should be called with error as first argument and result you need as secound argument. the secound argument is a ctx obejct, it's res attribute contains the result of the previous function call, you can save any object on ctx as you need.
.done(Function)
The callback function is called with error (null or undefined if not exist) and the result array when all the request get finished (or timeout reached).
Note, this function should only be called once.
License
MIT
About
A simple module for working with serial callbacks, works on node and browser