Fail Safe Queue
It's a very simple Queue of functions. But also let's you define, for each one, a rollback in case something goes wrong later on the queue stack calling.
Heavily inspired by caolan/async.
Installation
npm install fail-safe-queue --save
Quick Examples
Success example:
var queue =
Will echo:
+ up! 1
+ up! 2
+ up! 3
err null
results [ [ 1 ], [ 2 ], [ 3 ] ]
Fail example:
var queue =
Will echo:
+ up! 1
+ up! 2
- down! 1
err This method triggered an error :S
results [ [ 1 ] ]
API
queue(tasks, [callback])
Arguments
tasks
- It's an array of tasks. Each task could be a simple function to be called in order or an object with two functions,up: [Function(next)]
anddown: [Function(prev)]
.callback(err, results)
- An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to thetask
callbacks.