Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

promise.prototype.finally

es-shims6.1mMIT3.1.8TypeScript support: definitely-typed

ES Proposal spec-compliant shim for Promise.prototype.finally

Promise, promises, finally, promise.prototype.finally, ES7, ES8, ES2017, shim, polyfill, es-shim API

readme

promise.prototype.finally Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v3.1.8 - 2024-02-04

Commits

  • [Refactor] use es-errors where possible, so things that only need those do not need get-intrinsic 9f15e2a
  • [Deps] update call-bind, es-abstract, get-intrinsic 4dbd141
  • [Dev Deps] update aud, tape 3661fdb

v3.1.7 - 2023-09-13

Commits

  • [Deps] update define-properties, set-function-name 01d3f17

v3.1.6 - 2023-09-13

Commits

  • [Refactor] use set-function-name 903d207
  • [actions] update checkout action 594ef8e

v3.1.5 - 2023-08-30

Commits

  • [Deps] update define-properties, es-abstract 2ff6ac3
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, es6-shim, tape 4cacca4

v3.1.4 - 2022-11-07

Commits

  • [actions] reuse common workflows 1f2f581
  • [meta] add auto-changelog 382073c
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest, tape 82cee30
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, tape 7a16cda
  • [actions] update rebase action to use reusable workflow a3cefcf
  • [actions] update codecov uploader 63f0668
  • [Deps] update define-properties, es-abstract efeba8d

3.1.3 / 2021-10-04

  • [Refactor] update es-abstract; use call-bind instead of function-bind
  • [Deps] update es-abstract
  • [readme] add github actions/codecov badges
  • [meta] remove unneeded token; update checkout action
  • [actions] use node/install instead of node/run; use codecov action
  • [actions] add Require Allow Edits workflow
  • [actions] switch Automatic Rebase workflow to pull_request_target event
  • [Tests] increase coverage
  • [Tests] migrate tests to Github Actions (#29)
  • [Tests] run nyc on all tests; use tape runner; add implementation tests; mark failing impl tests as TODO
  • [Tests] skip "observable calls" tests in node 6-9
  • [Tests] add passing tests from https://github.com/tc39/test262/pull/2752
  • [Tests] refactor Subclass tests to capture receiver
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, es6-shim, tape

3.1.2 / 2019-12-11

  • [Refactor] use split-up es-abstract
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, safe-publish-latest
  • [Tests] up to node v12.12
  • [Tests] use shared travis-ci configs
  • [meta] add funding field
  • [actions] add automatic rebasing / merge commit blocking

3.1.1 / 2019-08-25

  • [Fix] finally receiver must only be an Object, not a Promise
  • [Deps] update define-properties, es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, covert, es6-shim, safe-publish-latest, tape
  • [Tests] up to node v12.9, v11.15, v10.16, v9.11, v8.16, v6.17, v4.9
  • [Tests] add test for non-Promise receiver
  • [Tests] use npx aud instead of nsp or npm audit with hoops

3.1.0 / 2017-10-26

  • [New] Add auto shim file, allowing clean 'import' (#12)
  • [Refactor] only call Promise#then for a brand check once, instead of twice.
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, nsp

3.0.1 / 2017-09-09

  • [Fix] ensure that the “then” brand check doesn’t cause an unhandled rejection warning (#10)
  • [Deps] update es-abstract, function-bind
  • [Dev Deps] update eslint, @ljharb/eslint-config, nsp, tape, @es-shims/api
  • [Tests] up to node v8.4; use nvm install-latest-npm so new npm doesn’t break old node; add 0.8
  • [Tests] restore ES5 tests
  • [Tests] refactor to allow for unshimmed tests

3.0.0 / 2017-07-25

  • [Breaking] update implementation to follow the new spec (#9)
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, es6-shim, nsp, safe-publish-latest, tape
  • [Tests] up to node v8.1, v7.10, v6.11, v4.8; improve matrix
  • [Tests] fix 0.10; remove 0.8

2.0.1 / 2016-09-27

  • [Fix] functions in IE 9-11 don’t have a name property (#3)

2.0.0 / 2016-08-21

  • Re-release.

1.0.1 / 2015-02-09

1.0.0 / 2014-10-11

  • Initial release.