luci-base: luci.js: add Promise.finally polyfill
Fixes: #2854 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
d01cdd98bb
commit
7c9d845d9b
1 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,20 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Promise.finally polyfill */
|
||||||
|
if (typeof Promise.prototype.finally !== 'function') {
|
||||||
|
Promise.prototype.finally = function(fn) {
|
||||||
|
var onFinally = function(cb) {
|
||||||
|
return Promise.resolve(fn.call(this)).then(cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.then(
|
||||||
|
function(result) { return onFinally.call(this, function() { return result }) },
|
||||||
|
function(reason) { return onFinally.call(this, function() { return Promise.reject(reason) }) }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class declaration and inheritance helper
|
* Class declaration and inheritance helper
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue