include proposed `Promise.prototype.finally`
See original GitHub issuebasically just:
/**
`finally` will be invoked regardless of the promise's fate just as native
try/catch/finally behaves
Synchronous example:
findAuthor() {
if (Math.random() > 0.5) {
throw new Error();
}
return new Author();
}
try {
return findAuthor(); // succeed or fail
} catch(error) {
return findOtherAuther();
} finally {
// always runs
// doesn't affect the return value
}
Asynchronous example:
findAuthor().catch(function(reason){
return findOtherAuther();
}).finally(function(){
// author was either found, or not
});
@method finally
@param {Function} callback
@return {Promise}
*/
finally(callback) {
let promise = this;
let constructor = promise.constructor;
return promise.then(value => constructor.resolve(callback()).then(() => value),
reason => constructor.resolve(callback()).then(() => { throw reason; }));
}
Questions:
- should 4.0.0’s
es6-promise/auto
polyfill the whole promise, or justfinally
iffinally
is not present? - should we wait a-bit longer or is the risk sufficiently low to just :shipit: cc @domenic
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Promise.prototype.finally() - JavaScript - MDN Web Docs
The finally() method of a Promise object schedules a function to be called when the promise is settled (either fulfilled or rejected).
Read more >promise.prototype.finally
This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies ...
Read more >tc39/proposal-promise-finally
Many promise libraries have a "finally" method, for registering a callback to be invoked when a promise is settled (either fulfilled, or rejected)....
Read more >Finally the Promise.prototype.finally() is available
Availability of Promise.prototype.finally() brings it to all the Promise-based API, like the global fetch() (used in the demos) and all ...
Read more >ES2018: `Promise.prototype.finally()`
The proposal “Promise.prototype.finally” by Jordan Harband is at stage 4. This blog post explains it.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@shirakaba this isn’t a future spec feature;
finally
is stage 4 - it’s already in the language (in ES2018).In other words, if the core TS library lacks a definition for
finally
, that’s a bug in TS.Okay, it looks like it may potentially even be a WebStorm IDE issue – Typescript has a lib called
lib.esnext.promise.d.ts
– importable via--lib esnext.promise
, but WebStorm’s language service does not have this library file, so I suspect I’d be unable to use it without issue.WebStorm’s language service has most of the TypeScript core libs, but also lacks
lib.es2018.d.ts
. Theirlib.esnext.full.d.ts
, like TypeScript’s official one, does not includefinally()
, either. I’ll have to look into it.