Closed AprilArcus closed 8 years ago
You might know that, but the program can't know that - it might be a Promise, or a generic thenable, or a normal value. By spec, anything await
ed must be coerced into a native Promise, whether it is one or not.
Thanks for the clarification! I was not aware that plain values were legal in that position.
What about
function test() {
return Promise.resolve(db.destroy).then(function () {});
}
?
@AprilArcus that would make a promise for the db.destroy
function - and if you did Promise.resolve(db.destroy())
then that would a) run synchronously instead of correctly on the next tick, and b) if that threw an exception, it would not create a rejected promise.
Thanks, I think I understand correctly now :)
Currently,
transpiles to
instead of
Why is this? We know the expression to the right of
await
must be a Promise, so this seems overcautious.