Skip to content

Instantly share code, notes, and snippets.

@kei0425
Last active February 15, 2017 03:32
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 kei0425/96c3096c92625ce4e362394ba4094f18 to your computer and use it in GitHub Desktop.
Save kei0425/96c3096c92625ce4e362394ba4094f18 to your computer and use it in GitHub Desktop.
function wait(t, callback) {
return new Promise(
(resolve, reject) => setTimeout(() => callback(resolve, reject), t));
}
async function main() {
await wait(1000, (resolve, reject) => {
console.log('resolve');
resolve();
});
console.log(1);
try {
await wait(1000, (resolve, reject) => {
console.log('reject');
reject('reason');
});
console.log(2);
} catch (e) {
console.log(e);
}
console.log(3);
try {
await wait(1000, (resolve, reject) => {
console.log('exception');
throw 'error';
});
console.log(4);
} catch (e) {
console.log(e);
}
console.log(5);
}
try {
main();
} catch (e) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment