Skip to content

Instantly share code, notes, and snippets.

@ajhsu
Created May 3, 2016 07:07
Show Gist options
  • Save ajhsu/1f04ecac7e31089158ae686f4776b2fe to your computer and use it in GitHub Desktop.
Save ajhsu/1f04ecac7e31089158ae686f4776b2fe to your computer and use it in GitHub Desktop.
// Async function
var getNum = function(){
return new Promise((resolve, reject) => {
// resolve(1);
reject('not found');
});
}
// A function that contains an async-call
async function asyncFun (){
var value = await getNum()
.then(x => x + 1)
.then(x => x + 1)
.then(x => x + 1)
.catch(err => Object({error: err}));
return value;
}
// Invoke the function
asyncFun()
.then(r => console.log(r))
.catch(r => console.err(r));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment