Created
June 2, 2017 21:24
-
-
Save jadaradix/6c72a08a9e980676a141afd487e7516b to your computer and use it in GitHub Desktop.
async-await-nodejs
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
'use strict'; | |
async function boot () { | |
async function getName () { | |
if (false) { | |
return new Promise( | |
resolve => { | |
setTimeout(() => resolve('James'), 1000); | |
} | |
); | |
} else { | |
return Promise.reject('not working'); | |
} | |
}; | |
try { | |
let name = await getName(); | |
console.log(`Name: ${name}`); | |
} catch (error) { | |
console.log(`Error: ${error}`); | |
} | |
}; | |
boot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment