This is fork of original Promise.prototype.finally
with one small addition:
In case of rejection finally
receives error (reason) as argument.
It allows to decide which error should be passed further in promise chain.
In many cases original error is more helpful for debugging than own finally error.
Let's take an example.
Problem:
Promise ; // here we get the stacktrace of cleanup error, not original error that rejected the promise chain
Solution with original finally
:
Promise ;
Solution with modified finally
receiving error argument:
Promise ;
See more details in this discussion.
Installation:
npm i promise.prototype.finally.err
Usage:
;
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 = ;var promiseFinally = ; var resolved = Promise;var rejected = Promise; ; ; ; promiseFinally; // will be a no-op if not needed resolved; rejected; rejected;
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