Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 

PromiseA

A simple Promises/A+ implementation.

Useage

// useage 1
var read = function(path) {
    var p = Promise();
    
    fs.readFile(path, function(err, data) {
        if(!err) p.resolve(data);
        else p.reject(err);
    });
    
    return p;
};

// useage 2
var write = function(data) {
    return Promise(function(resolve, reject) {
        fs.writeFile('bar.js', function(err) {
            if(!err) resolve();
            else reject(err);
        });
    });
};

// useage 3
var sleep = function(ms) {
    return function(v) {
        var p = Promise();

        setTimeout(function() {
            p.resolve(v);
        }, ms);

        return p;
    };
};

read('foo.js')
    .then(sleep(1000))
    .then(write)
    .then(sleep(1000))
    .then(function() {
        console.log('done!');
    });

API list

constructor

  • Promise()

instance methods

  • then()

  • resolve()

  • reject()

static methods

  • Promise.resove()

  • Promise.reject()

  • Promise.all()

  • Promise.any()

Idea About Promise

JavaScript Promise

Licence

MIT.

About

A simple Promises/A+ implementation.

Resources

Releases

No releases published

Packages

No packages published