Gives "Unhandled promise rejection"(async () => { const promise = new Promise((resolve, reject) => { reject("Failed!") }); await new Promise(resolve => setTimeout(resolve, 100)); await promise; })().then(console.log).catch(console.error); Catches the error as expected(async () => { const promise = new Promise((resolve, reject) => { reject("Failed!") }); await promise; })().then(console.log).catch(console.error); I have been banging my head against this for awhile, the use case might seem weird, in this scenario you could simply just(async () => { await new Promise(resolve => setTimeout(resolve, 100)); await new Promise((resolve, reject) => { reject("Failed!") }); })().then(console.log).catch(console.error); Is this a bug, or did i miss something?
Submitted May 21, 2020 at 07:35PM by Zjaelly
No comments:
Post a Comment