When we create a Promise
, the executor function is called immediately but the resolve
callback is the one which gets executed asynchronously. This means that if I do some heavy work inside the executor function resulting in a result that gets passed to the resolve callback, then all that work gets executed in the same thread in a blocking manner, and only the result gets passed to us asynchronously via the callback. I hope this understanding is correct.
Does the asynchronous part inside the executor function start only when a pre-defined async Web API like fetch or timeout is called, or when resolve or reject callbacks are called? Can't we write our own block of code that gets executed in a parallel thread?