-
Notifications
You must be signed in to change notification settings - Fork 0
A constant that marks an argument position as being reserved for a callback function of the asynchronous function to add. See Unify.add() for usecases.
Creates and returns a new Unify instance without adding an initial asynchronous function. This can be very useful if the functions to unify are added within a loop.
Example:
var unified = Unify.create();
for( ... ) {
unified.add( function() { ... }, ... );
}
unified.invoke( function( results ) { ... } );
Example link: http://jsfiddle.net/6CSPT/
Creates and returns a unify instance just as Unify.create()
does, but directly accepts an asynchronous function with according arguments. This can be used for elegant chaining of multiple function call additions.
The function will be stored together with the arguments that should be passed to it on its invocation. There can be as many arguments as needed and of any type. The special marker constant Unify.CALLBACK
can be used to mark an argument position as being a callback for the asynchronous function. This constant can be used as often as there are callbacks in the function (see example 3). It is even possible to mark a property within a simple object literal argument as callback (see example 4).
Example 1:
Unify.add( myAsyncFunction, Unify.CALLBACK );
Example 2:
Unify.add( myAsyncFunction, firstArgument, Unify.CALLBACK, thirdArgument, forthArgument );
Example 3:
Unify.add( myAsyncFunction, firstArgument, Unify.CALLBACK, Unify.CALLBACK );
Example 4:
Unify.add( myAsyncFunction, {
callback: Unify.CALLBACK,
arg: "foo"
} );
Example link: http://jsfiddle.net/FYerW/
See the doc for the static Unify.add() method. You can use a combination of the static method and this one for chaining together the additions of multiple asynchronous functions.
Example:
Unify.add( myAsyncFunction1, Unify.CALLBACK ) // call static add
.add( myAsyncFunction2, firstArgument, Unify.CALLBACK, thirdArgument, forthArgument ) // call instance add
.add( myAsyncFunction3, firstArgument, Unify.CALLBACK, Unify.CALLBACK ) // call instance add
// ...
Example link: http://jsfiddle.net/HfPAT/
Invokes all add asynchronous functions and when returned, calls callback
with all collected results. The only parameter passed to callback is an array with an entry for the result arguments of each unified function in the order they were added.
Example:
Unify.add( myAsyncFunction1, Unify.CALLBACK )
.add( myAsyncFunction2, firstArgument, Unify.CALLBACK, thirdArgument, forthArgument )
.add( myAsyncFunction3, firstArgument, Unify.CALLBACK, Unify.CALLBACK )
.invoke( function( results ) {
// do something with the results
} );
Example link: http://jsfiddle.net/6CSPT/