Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active December 7, 2016 13:25
Show Gist options
  • Select an option

  • Save aherve/870a6469e232c1d1e4363ee46effef46 to your computer and use it in GitHub Desktop.

Select an option

Save aherve/870a6469e232c1d1e4363ee46effef46 to your computer and use it in GitHub Desktop.
// ----- Without async ----- //
function regularPlusOne (i: number): Promise<number> {
return new Promise(resolve => {
resolve(i + 1)
})
}
// ----- With async ----- //
async function plusOne (i: number): Promise<number> {
return i + 1
}
// Both functions can be used as
plusOne(1)
.then(plusOne)
.then(plusOne)
.then(console.log) // outputs 4
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment