Q.Pipe Class
Sets up control flows involving multiple callbacks and dependencies Usage:
Constructor
Q.Pipe
()
Example:
var p = Q.pipe(['user', 'stream], function (params, subjects) { // arguments that were passed are in params.user, params.stream // this objects that were passed are in subjects.user, subjects.stream }); mysql("SELECT FROM user WHERE userId = 2", p.fill('user')); mysql("SELECT FROM stream WHERE publisherId = 2", p.fill('stream'));
The first parameter to p.fill() is the name of the field to fill when it's called You can pass a second parameter to p.fill, which can be either: true - in this case, the current function is ignored during the next times through the pipe a string - in this case, this name is considered unfilled the next times through this pipe an array of strings - in this case, these names are considered unfilled the next times through the pipe
Methods
add
-
requires
-
maxTimes
-
callback
Adds a callback to the pipe with more flexibility
Parameters:
-
requires
ArrayOptional. Pass an array of required field names here. Alternatively, pass an array of objects, which should be followed by the name of a Q.Event to wait for.
-
maxTimes
NumberOptional. The maximum number of times the callback should be called.
-
callback
FunctionOnce all required fields are filled, this function is called every time something is piped. It is passed four arguments: (params, subjects, field, requires) If you return false from this function, it will no longer be called for future pipe runs. If you return true from this function, it will delete all the callbacks in the pipe.
Returns:
fill
-
field
-
ignore
Makes a function that fills a particular field in the pipe and can be used as a callback
Parameters:
Returns:
Returns a callback you can pass to other functions.
on
-
field
-
callback
Adds a callback to the pipe
Parameters:
-
field
StringPass the name of a field to wait for, until it is filled, before calling the callback.
-
callback
FunctionThis function is called as soon as the field is filled, i.e. when the callback produced by pipe.fill(field) is finally called by someone. The "this" and arguments from that call are also passed to the callback. The callback receives the same "this" and arguments that the original call was made with. It is passed the "this" and arguments which are passed to the callback. If you return true from this function, it will delete all the callbacks in the pipe.