Instantiates, Configures and begins execution of a new Sequencer.
The purpose of this function is to operate as a synchronous scaffolding for asynchronous functionality. An array of independent aSynchronous events that rely on the results passed between each other is passed, then executed in the order specified in the sequence registry.
Each function touched by the sequencer should be written such that they can take the same arguments passed to any other function in the sequencer for the purposes of convention over configuration, including shared config. Functioned consumed by the sequencer should follow the convention of function(opts, callback) and callback (err, data) as per http://blog.gvm-it.eu/post/22040726249/callback-conventions-in-nodejs-how-and-why and other resources.
Each instance of a sequence should be thought of as a contained application with its own config, passed in the form of args.
The data returned from each function in the sequence will be made available to the following function in the sequence.
A portion of the sequencer itself will be passed into each stage of the sequence so that it can track it's current execution stage In the analogy of a close application, the sequencer will be the application context.
The sequencer must be instantiated, multiple sequencers can be instantiated but the developer must handle the asynchronous nature of them as you would any other asynchronous functionality.
The purpose of this function is to operate as a synchronous scaffolding for asynchronous functionality. An array of independent aSynchronous events that rely on the results passed between each other is passed, then executed in the order specified in the sequence registry.
Each function touched by the sequencer should be written such that they can take the same arguments passed to any other function in the sequencer for the purposes of convention over configuration, including shared config. Functioned consumed by the sequencer should follow the convention of function(opts, callback) and callback (err, data) as per http://blog.gvm-it.eu/post/22040726249/callback-conventions-in-nodejs-how-and-why and other resources.
Each instance of a sequence should be thought of as a contained application with its own config, passed in the form of args.
The data returned from each function in the sequence will be made available to the following function in the sequence.
A portion of the sequencer itself will be passed into each stage of the sequence so that it can track it's current execution stage In the analogy of a close application, the sequencer will be the application context.
The sequencer must be instantiated, multiple sequencers can be instantiated but the developer must handle the asynchronous nature of them as you would any other asynchronous functionality.
Parameters:
| Name | Type | Description |
|---|---|---|
config|sequence |
Object | Array | object containing keys ['sequence', 'args', 'callback'] or array of {Function|Array}. If a config object is passed, only 1 argument must be passed. If arguments are implied, only 3 must be passed. |
args |
Object | (optional when config object is passed otherwise required) args object containing args to be made available to each function within the sequence |
callback |
function | (optional) callback to execute after the sequence has completed. |
- Source:
Returns:
- Type
- Sequencer
Examples
//Return the sequencer for use elsewhere
//Implied args
var ssync = require('bsync')
var sequence1 = bsync.sequence([
function1,
function2
],{
arg1 : "String",
arg2 : true
},function(err, data) {
//Do something with the result of the final output
});
//Explicit args
ssync.sequence({
sequence:[
function1,
function2
],
args: {
arg1 : "String",
arg2 : true
},
callback: function(err, data) {
//Do something with the result of the final output
}
});
//Concurrent functions
ssync.sequence([
[ function1, function2 ],
],
null,
function(err, data) {
// the merged results of function1 and function2 will be
// passed here instead of just the output of function2
});