Skip to content

Instantly share code, notes, and snippets.

@n370
Last active December 8, 2018 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n370/6a3402a2ce780d02642cc85278ac5e77 to your computer and use it in GitHub Desktop.
Save n370/6a3402a2ce780d02642cc85278ac5e77 to your computer and use it in GitHub Desktop.
async function example
async function myAsyncFuntion() {
try {
const ok = await (() => new Promise((resolve, reject) => {
setTimeout(() => {
const luckyEnough = Math.round(Math.random() * 10) % 2 === 0;
if (luckyEnough) {
resolve('ok');
} else {
reject('err');
}
}, 2000);
}))();
console.log(ok);
} catch (err) {
console.error(err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment