asyncbuilder
v1.1.1
Published
simple semi-asynchronous array builder
Downloads
59
Readme
asyncbuilder
- builds an array containing a mix of immediate and async results
- follows node convention of using callbacks with signature
cb(err, results)
- useful for building a sequential list in the order that async operations are invoked
install
npm install asyncbuilder
usage
// new is optional
var ab = new asyncbuilder(mainCallBack);
// call any number of times... for sync
ab.append(something);
// or for async
var cb = ab.asyncAppend(); // returns callback
someAsyncOperation(cb);
// call this at least once
ab.complete();
no
mainCallBack()
will happen until you issue acomplete()
mainCallBack(null, results)
is invoked once after the lastcb()
with no errors.mainCallBack(err)
is invoked once after the firstcb(err)
.the original order of
append()
andasyncAppend()
operations is respected in the results, even if asyncAppend results arrive out of order.if there are only append operations, or no appends at all,
complete()
will triggermainCallBack()
on nextTick.calling
append()
orasyncAppend()
aftercomplete()
will result in an error.
note
- it doesn't make sense to call
asyncAppend()
from within an async operation. Ordering will be wrong, andcomplete()
will probably have been called already. Instead, callasyncAppend()
before the async operation and pass the function returned byasyncAppend()
as the operation's async callback
license
Copyright (c) 2015-2024 Jürgen Leschner, MIT license