Show:

Q.Pipe Class

Module: Q

Sets up control flows involving multiple callbacks and dependencies Usage: 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 Q.Cache constructor

Constructor

Q.Pipe

()

Item Index

Methods

Methods

add

(
  • 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.

add

(
  • requires
  • maxTimes
  • callback
)

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.

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 Boolean | String | Array

    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.

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