Package Exports
- chainlink
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chainlink) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Chainlink 
An asynchronous task container.
Installation
npm install chain --saveExample
var Chain = require('chainlink');
var chain = new Chain();
chain.link(function(next, arg) {
console.log(arg);
next('bar');
});
chain.link(function(next, arg) {
console.log(arg);
next('baz');
});
chain.invoke(function(err, arg) {
console.log(arg);
}, 'foo');Output:
foo
bar
bazAPI
new Chain()
Takes no arguments. Returns a new Chain instance.
.link(callback)
Arguments
- callback
Function(next, args...): The function to link to the chain.- Callbacks will be passed a
next()method which must be called, and all of the arguments passed to.invoke()or the last call tonext(). - Any arguments passed to the
next()method will be passed to the next callback in the chain. - Callbacks can throw an exception synchronously or call the
next.error(err)method to skip all remaining callbacks in the chain. The done callback passed to invoke will be called and passed the error as a non-null first argument.
- Callbacks will be passed a
Returns
A reference to the chain.
.unlink(callback)
Arguments
- callback
Function: The function to unlink from the chain.
Returns
An array of all callbacks unlinked from the chain.
.invoke(done, args...)
Arguments
- done
Function(err, args...): The function to be called after all callbacks in the chain have been called.- The
errparameter will be null if no callbacks threw synchronous errors or called thenext.error(err)method, otherwise it will be the raised error.
- The
- args...: All the arguments passed to the
next()method by the last callback in the chain.
Returns
A reference to the chain.
Behavior
Recursion
Callbacks can recursively invoke the chain without any adverse effects.
Callback link/unlink
If a callback calls the link or unlink method of its own chain, the current invocation will not be affected. Future invocations of the chain will reflect the linked or unlinked callbacks.