1.1.0 • Published 11 years ago

deferreds v1.1.0

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

Deferreds.js

Build Status

Main documentation is right here!

Deferreds.js is a utility library centered around working with Deferred objects. The main goal is to do for Deferred objects what async.js does for Node-style asynchronous functionsthat is, provide many common higher-order functions (map, reduce, filter, etc.) accepting potentially-asynchronous Deferred objects as arguments.

Just like async.js, deferreds.js provides several flow control functions. To give you an idea of what these look like, here's perhaps the most useful function, pipe (called "waterfall" in async.js):

pipe([
    function() {
        var deferred = new Deferred();
        setTimeout(function() {
            deferred.resolve('one', 'two');
        }, 10);
        return deferred.promise();
    },
    function(arg1, arg2) {
        console.log(arg1); //> 'one'
        console.log(arg2); //> 'two'

        var deferred = new Deferred();
        setTimeout(function() {
            deferred.resolve({
                arg1: arg1,
                arg2: arg2,
                arg3: 'three'
            });
        }, 10);
        return deferred.promise();
    },
    function(result) {
        console.log(result.arg1); //> 'one'
        console.log(result.arg2); //> 'two'
        console.log(result.arg3); //> 'three'

        var deferred = new Deferred();
        setTimeout(function() {
            deferred.resolve(['four']);
        }, 10);
        return deferred.promise();
    }
]).then(function(result) {
    console.log(result); //> ['four']
});
1.1.0

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.3.1

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago