once-done
Call a callback when a Promise is settled.
Last updated 11 years ago by belym.a.2105 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install once-done 
SYNC missed versions from official npm registry.

once-done

Build Status

Call a function when a Promise is settled.

Implementation of Promise.prototype.finally as non-method function.

Written in ES6, transpiled by Babel.

Install

npm install once-done

Usage

Use it like try..finally for promises:

var onceDone = require('once-done');

var file = getFile();

var someResultPromise = handleFileAsync(); //someStatsPromise may be rejected

onceDone(someResultPromise, function () {
    file.close(); //Close the file in any situation
    return file.deleteAsync(); //You may return Promise, and it will be resolved!
})
.then(function (result) {
    //Handle the result
})
.catch(function (reason) {
    //Check a reason of rejection
});

Current Tags

  • 1.0.2                                ...           latest (11 years ago)

3 Versions

  • 1.0.2                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 9
Today 3
This Week 9
This Month 9
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE