⬅️ Execute Program JavaScript Concurrency
Using Resolve later
- We can store the
resolve
function in a variable. This allows us to “capture” theresolve
function, then use it outside of thenew Promise
constructor.
- The net effect of this is: we can split promises into two pieces. We might pass the
resolve
function to one part of the system, then pass the promise itself to a totally different part. When the “reading” side tries to look inside the promise with athen
, it will have to wait until the “writing” side has calledresolve
.
- we can only resolve the promise once