Name: Promise.prototype.finally
Owner: ECMAScript Shims
Description: ES Proposal spec-compliant shim for Promise.prototype.finally
Created: 2016-08-20 07:16:06.0
Updated: 2018-05-18 15:55:03.0
Pushed: 2018-01-05 20:07:45.0
Homepage: https://github.com/tc39/proposal-promise-finally
Size: 47
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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:
assert = require('assert');
promiseFinally = require('promise.prototype.finally');
resolved = Promise.resolve(42);
rejected = Promise.reject(-1);
iseFinally(resolved, function () {
assert.equal(arguments.length, 0);
return Promise.resolve(true);
hen(function (x) {
assert.equal(x, 42);
iseFinally(rejected, function () {
assert.equal(arguments.length, 0);
atch(function (e) {
assert.equal(e, -1);
iseFinally(rejected, function () {
assert.equal(arguments.length, 0);
throw false;
atch(function (e) {
assert.equal(e, false);
iseFinally.shim(); // will be a no-op if not needed
lved.finally(function () {
assert.equal(arguments.length, 0);
return Promise.resolve(true);
hen(function (x) {
assert.equal(x, 42);
cted.finally(function () {
assert.equal(arguments.length, 0);
atch(function (e) {
assert.equal(e, -1);
cted.finally(function () {
assert.equal(arguments.length, 0);
throw false;
atch(function (e) {
assert.equal(e, false);
Simply clone the repo, npm install
, and run npm test
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