proposal-promise-finally | ECMAScript Proposal , specs , and reference | Reactive Programming library
kandi X-RAY | proposal-promise-finally Summary
kandi X-RAY | proposal-promise-finally Summary
ECMAScript Proposal, specs, and reference implementation for Promise.prototype.finally. Spec drafted by @ljharb, following the lead from the cancelable promise proposal. Get the polyfill/shim on npm. This proposal is currently stage 4 of the process.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of proposal-promise-finally
proposal-promise-finally Key Features
proposal-promise-finally Examples and Code Snippets
Community Discussions
Trending Discussions on proposal-promise-finally
QUESTION
The TC39 proposal-promise-finally
, which is now part of the ES2018 specification, lists the following key points also paraphrased on MDN to describe exactly what the method does.
promise.finally(func)
is similar topromise.then(func, func)
, but is different in a few critical ways:
- When creating a function inline, you can pass it once, instead of being forced to either declare it twice, or create a variable for it
- A
finally
callback will not receive any argument, since there's no reliable means of determining if the promise was fulfilled or rejected. This use case is for precisely when you do not care about the rejection reason, or the fulfillment value, and so there's no need to provide it.- Unlike
Promise.resolve(2).then(() => {}, () => {})
(which will be resolved withundefined
),Promise.resolve(2).finally(() => {})
will be resolved with2
.- Similarly, unlike
Promise.reject(3).then(() => {}, () => {})
(which will be resolved withundefined
),Promise.reject(3).finally(() => {})
will be rejected with3
.However, please note: a
throw
(or returning a rejected promise) in thefinally
callback will reject the new promise with that rejection reason.
In other words, a concise polyfill using a Promise
implementation that conforms to the Promises/A+ specification is as follows (based on the answers by @Bergi and @PatrickRoberts).
ANSWER
Answered 2019-May-09 at 18:20This demonstrates that the semantics for the settled state of the resulting promise differ from the analogue
try...finally
block.
Not really, you just used the "wrong" try
/finally
syntax in your comparison. Run it again with
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install proposal-promise-finally
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page