implement Promise.prototype.finally()
2022年5月1日小于 1 分钟
implement Promise.prototype.finally()
Question
Promise.prototype.finally() could be used to run a callback when a promise is settled(either fulfilled or rejected).
Notice that the callback passed finally()
doesn't receive any argument, meaning it doesn't modify the value in the promise chain (care for rejection).
Code
/**
* @param {Promise<any>} promise
* @param {() => void} onFinally
* @returns {Promise<any>}
*/
function myFinally(promise, onFinally) {
// your code here
}