latest-promise

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i latest-promise

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • bahmutov