1.0.0 • Published 7 years ago

jquery-deferred-sequence v1.0.0

Weekly downloads
2
License
(GPL-2.0 OR MIT)
Repository
github
Last release
7 years ago

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.