simple-join
Stuidly simple library to help join asynchronous callbacks in Javascript
Install
$ npm install simple-join
Usage
Simple joining
var join = ; var wait = 2{ console; }; ; ;
Simple joining, with error & success information
var join = ; var wait = 2{ console; //{"total":2,"errors":1,"success":1,"messages":["my error message"]} }; ; ;
Methods
join(num,callback)
Parameters:
num
(number) - number of joins to be comlpeted before running callbackcallback
(function) - callback function to be run when all joins are completed. Passed the status object (see join.status method)
Returns:
- (object) new instance of the object
Example:
var wait = 3{ //Run when we've joined all 3 };
join.done(num)
Signals that a join(s) is completed
Parameters:
num
(number, optional) - number of joins to be crossed off the list, default is 1
Returns:
- (number) number of joins that we're still waiting for
Example:
wait; wait;
join.success(num)
Signals that a join(s) is completed, and was 'successful'
Parameters:
num
(number, optional) - number of joins to be crossed off the list, default is 1
Returns:
- (number) number of joins that we're still waiting for
Example:
wait; wait;
join.error(val)
Signals that a join(s) is completed, but with an 'error'.
Parameters:
val
(number, optional) - number of joins to be crossed off the list, default is 1
OR
val
(string, optional) - error message to be recorded
Returns:
- (number) number of joins that we're still waiting for
Example:
wait; wait; wait;
join.status()
Get the join status object (same as object passed to the callback)
Parameters: None
Returns (object):
total
(number) : total number of joins when join was createdsuccess
(number) : number of joins completed that were successful (via join.success)errors
(number) : number of joins that had errors (via join.error)messages
(array) : array of errors messages (via join.error)
Example:
waitstatus;
"total":2 "success":1 "errors":1 "messages":"My error message"