Hacker News new | ask | show | jobs
by kesor 2149 days ago
the execution starts when the function is called - not when "await" is prepended to its result.
1 comments

Arguably correct but possibly misleading.

The asynchronous portion of the work is enqueued when the function is called, but does not start executing until it's scheduled, which can't happen until the current task ends or is blocked by an await. This is useful, as it means a promise can't settle before you've had a chance to add handlers; otherwise you might sometimes get UnhandledPromiseRejections because of an unavoidable race condition.

I said arguably correct because there's nothing stopping the function from doing a portion of the work synchronously, which would mean the work as a whole starts with the function call.