Created
May 3, 2016 07:07
-
-
Save ajhsu/1f04ecac7e31089158ae686f4776b2fe to your computer and use it in GitHub Desktop.
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
// 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