Skip to content

Instantly share code, notes, and snippets.

@dibikhin
Last active June 10, 2020 11:13
Show Gist options
  • Save dibikhin/d3e614448e0b5400e326bd4686f87292 to your computer and use it in GitHub Desktop.
Save dibikhin/d3e614448e0b5400e326bd4686f87292 to your computer and use it in GitHub Desktop.
Asyncify and wrap with catch
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