Skip to content

AndreyBelym/once-done

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
});

About

Call callback when a Promise is settled

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published