Last active
May 13, 2019 10:45
-
-
Save matinrco/8b7bcfcdb3725a069adb399d1d0c99b3 to your computer and use it in GitHub Desktop.
Sample javascript / nodejs / ecma6 async & await
This file contains hidden or 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
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