Functional async flow control library. Turn your asynchronous code into bite-sized synchronous looking functions.
npm install breeze
Node.js / Browserify
var breeze =
breeze(step)- Initialize breeze flow system, supports initial
.pass(value)- Introduce new value into flow system, argument is appended to system arguments passed through
.when(check, step)- When
checkis truthy, add
stepto the stack
.maybe(check, step)- When
checkis truthy, add
stepto the stack, sugar for
.some(check, step)- When
checkis truthy and no other
nonehas ran, add to the stack
.none(step)- Whenever no
somehave ran, add callback to the stack
.then(step)- Add callback to stack
.each(iterables, iteratee, step)- Iterate over an object / array and invoke a method for each entry.
iterablesis not a reference therefore, you must properly store
iterablesoutside of the flow if you plan to update or modify the object.
.catch(step)- Any error caught will terminate stack and be sent here
.deferred()- Returns a deferred promise system, allowing for a passable then / catch.
.reset()- Reset current system
step method passed through breeze has a very small API, providing any
arguments stored within the system passed through either the
.pass methods, and the
next callback method which is explained below.
function step (next, arguments...)
next method is the step callback system, it provides utility for short-circuiting the step system with an error, passing additional arguments along the chain, and skipping steps completely.
return next(err, arguments...)
next method supports additional modes explained below.
When a truthy
err is passed the system will short-circuit (no other actions will be taken) and
.catch will be triggered.
promise is passed the system will attach to either a
then / catch or
.then(success, catch) method style depending on the promise type passed.
Whenever the promises
then / then success method is invoked, any
arguments passed along with the initial promise are placed at the front of the arguments array, and the success arguments will be last.
This allows you to chain multiple promises while still passing values down the chain.
When you pass the string
skip as the first argument in the
next method, the next step in the sequence will be skipped completely.
You can skip multiple steps by providing a number as the second argument to
next equalling the number of steps you wish to skip. Defaults to
next('skip', 1 /* optional; number of steps to skip */)
Check out the examples directory for more in-depth examples and tutorials of how to use breeze.
Licensed under The MIT License.