Show:

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

Item Index

Methods

Methods

add

(
  • requires
  • maxTimes
  • callback
)
Q.Pipe chainable

Adds a callback to the pipe with more flexibility

Parameters:

  • requires Array

    Optional. 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 Number

    Optional. The maximum number of times the callback should be called.

  • callback Function

    Once 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
)
Function

Makes a function that fills a particular field in the pipe and can be used as a callback

Parameters:

  • field String

    For error callbacks, you can use field="error" or field="users.error" for example.

  • ignore Object

    Optional. If true, then ignores the current field in subsequent pipe runs. Or pass the name (string) or names (array) of the field(s) to ignore in subsequent pipe runs.

Returns:

Function:

Returns a callback you can pass to other functions.

on

(
  • field
  • callback
)

Adds a callback to the pipe

Parameters:

  • field String

    Pass the name of a field to wait for, until it is filled, before calling the callback.

  • callback Function

    This 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.

run

(
  • field
)
Number

Runs the pipe

Parameters:

  • field String

    optionally indicate name of the field that was just filled

Returns:

Number:

the number of pipe callbacks that wound up running