promise.prototype.finally

3.1.8last stable release 1 year ago
Complexity Score
Low
Open Issues
2
Dependent Projects
140
Weekly Downloadsglobal
1,311,879

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

promise.prototype.finally

ES Proposal spec-compliant shim for Promise.prototype.finally. Invoke its “shim” method to shim Promise.prototype.finally if it is unavailable or noncompliant. Note: a global Promise must already exist: the es6-shim is recommended.

This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies with the proposed spec.

Most common usage:

var assert = require('assert');
var promiseFinally = require('promise.prototype.finally');

var resolved = Promise.resolve(42);
var rejected = Promise.reject(-1);

promiseFinally(resolved, function () {
    assert.equal(arguments.length, 0);

    return Promise.resolve(true);
}).then(function (x) {
    assert.equal(x, 42);
});

promiseFinally(rejected, function () {
    assert.equal(arguments.length, 0);
}).catch(function (e) {
    assert.equal(e, -1);
});

promiseFinally(rejected, function () {
    assert.equal(arguments.length, 0);

    throw false;
}).catch(function (e) {
    assert.equal(e, false);
});

promiseFinally.shim(); // will be a no-op if not needed

resolved.finally(function () {
    assert.equal(arguments.length, 0);

    return Promise.resolve(true);
}).then(function (x) {
    assert.equal(x, 42);
});

rejected.finally(function () {
    assert.equal(arguments.length, 0);
}).catch(function (e) {
    assert.equal(e, -1);
});

rejected.finally(function () {
    assert.equal(arguments.length, 0);

    throw false;
}).catch(function (e) {
    assert.equal(e, false);
});

Tests

Simply clone the repo, npm install, and run npm test

Thanks

Huge thanks go out to @matthew-andrews, who provided the npm package name for v2 of this module. v1 is both in the original repo and preserved in a branch

Dependencies

CVE IssuesActive
0
Scorecards Score
4.40
Test Coverage
98.00%
Follows Semver
Yes
Github Stars
138
Dependenciestotal
15
DependenciesOutdated
2
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute promise.prototype.finally in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install promise.prototype.finally
Processing...
Done

14 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.