latest-promise
Pick latest promise when multiple ones are running
Last updated 6 years ago by bahmutov .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install latest-promise 
SYNC missed versions from official npm registry.

latest-promise

Pick latest promise when multiple ones are running

Circle CI

npm install --save latest-promise

Then pass each promise through the exported function. All but latest promise will be rejected, you can check if the rejection is due to being obsolete

var pickLatest = require('latest-promise');
var first = pickLatest(makeSlow());
var second = pickLatest(makeFast());
// first promise takes a long time to finish, while second is quick
// second promise has valid value, but the first one gets rejected
first.catch(function (err) {
    if (pickLatest.wasObsolete(err)) {
        // well, this promise finished AFTER second
        // and should be ignored
    }
});

See blog post Pick latest promise

Small print

Author: Gleb Bahmutov © 2015 @bahmutov glebbahmutov.com glebbahmutov.com/blog

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet / open issue on Github

Current Tags

  • 1.1.0                                ...           latest (6 years ago)

3 Versions

  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |