Last active
June 10, 2020 11:13
-
-
Save dibikhin/d3e614448e0b5400e326bd4686f87292 to your computer and use it in GitHub Desktop.
Asyncify and wrap with catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleErrors = (err) => { console.error(err); return null } | |
const wrap = (f) => | |
(...args) => | |
( | |
( | |
async () => f(...args) | |
)() | |
).catch(handleErrors) | |
const wrapped = wrap( | |
(x) => { | |
console.log(x) | |
// throw new Error('test error') | |
return null | |
} | |
) | |
;( | |
( | |
async() => await wrapped('a') | |
)() | |
).then() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment