1.0.0 • Published 7 years ago
jquery-deferred-sequence v1.0.0
jQuery Deferred Sequence
Allows a value to be sequentially processed through a list of objects, usually Deferred objects that represent asynchronous events.
var value = 0,
items = [
function( value ) {
return value + 1;
},
function( value ) {
var dfd = $.Deferred();
setTimeout(function() {
dfd.resolve( value * 2 );
}, 1000 );
return dfd;
},
function( value ) {
return value * value;
}
],
sequence = $.Deferred.Sequence( items );
sequence.reduce( value, function( func, value ) {
return $.when( func( value ) );
}).done(function( value ) {
console.log( value ); // => 4
});
Methods
- reduce( intialValue, callbackFunction , context ) Promise
Apply a function against each item in the sequence, optionally calling the function with the specified context.
Properties
head Deferred
A deferred object representing the beginning of the sequence.items Array, Object
The items given to the sequence on initialization.master Deferred
A deferred object which tracks the aggregate state of all the deferreds in the sequence.tail Deferred
A deferred object representing the end of the sequence.
License
Copyright (c) 2013 Kyle Florence
Dual licensed under the MIT and GPLv2 licenses.
1.0.0
7 years ago