From ff2b8fac7a0f4af4e9615ea9d7d0551fd6929f0c Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Fri, 2 Oct 2020 14:54:57 +0200 Subject: [PATCH] Promise.try shim --- src/promise-try-shim.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/promise-try-shim.js diff --git a/src/promise-try-shim.js b/src/promise-try-shim.js new file mode 100644 index 0000000..aa69b9d --- /dev/null +++ b/src/promise-try-shim.js @@ -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()); + }); + }; +} \ No newline at end of file