Promise.try shim

This commit is contained in:
Ewout Stortenbeker 2020-10-02 14:54:57 +02:00
parent 6d5956abfd
commit ff2b8fac7a

9
src/promise-try-shim.js Normal file
View file

@ -0,0 +1,9 @@
// Polyfill for Promise.try, promisifies synchronous code,
// resolving with function's return value and catching synchronous errors with a promise rejection
if (!Promise.try) {
Promise.try = function(fn) {
return new Promise(resolve => {
resolve(fn());
});
};
}