Skip to content

Instantly share code, notes, and snippets.

@matinrco
Last active May 13, 2019 10:45
Show Gist options
  • Save matinrco/8b7bcfcdb3725a069adb399d1d0c99b3 to your computer and use it in GitHub Desktop.
Save matinrco/8b7bcfcdb3725a069adb399d1d0c99b3 to your computer and use it in GitHub Desktop.
Sample javascript / nodejs / ecma6 async & await
const asyncAction = ( name )=>{
return new Promise(( resolve , reject )=>{
setTimeout(()=>{
resolve("kk , promise resolved "+ name +" !");
//reject("rejected")
},3000);
});
};
(async ()=>{
try {
const result = await asyncAction("John");
console.log(result);
}catch (e) {
console.log(e)//if reject from asyncAction called , output will be "rejected"
}
process.exit(1);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment