Skip to content

Instantly share code, notes, and snippets.

@jonathanmv
Created March 16, 2018 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanmv/ab501e408d227cadcb466a0501fdbb1b to your computer and use it in GitHub Desktop.
Save jonathanmv/ab501e408d227cadcb466a0501fdbb1b to your computer and use it in GitHub Desktop.
To check if await can be chained to then or catch
const l = console.log.bind(console)
const a = () => new Promise(resolve => setTimeout(() => resolve('done'), 1000))
const b = () => new Promise((_, reject) => setTimeout(() => reject('error'), 1000))
const c = async () => {
(await a()).then(l)
(await b()).catch(l)
}
c().then(() => l(`it can be done!!`))
.catch(({message}) => l(`Sorry dude: ${message}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment