2 ms·
That may be an implementation detail, but to a programmer, promises and thus async/await are just a resource that represents some background operation with some
by megous 7y ago
That may be an implementation detail, but to a programmer, promises and thus async/await are just a resource that represents some background operation with some side effect attached to some undetermined time in the future when the promise settles, if ever.
You get a reference to it and it's a resource to manage manually. You need to ensure that the side effect you attached to it at one time will not mess up anything in the future, despite not knowing in what situatuion in the future it will be resolving. User might have done many other operations with tha app in the meantime, etc.
You may also want to carry around an AbortController, in case you may need to cancel the operation behind the promise (like a fetch).
So promises are just references to some resources.
Async functions actually make the management of async jobs harder, since you're basically encoding a sequence of jobs into the structure of the functions you define and you don't even see the promises behind those, and you'll not have control over their execution from the outside, unless you explicitly code for it at every point.
You don't get to say: ok, whatever's going on now with all my data fetching async functions that may be currently running, I want to pause them in whatever state they may be now. Or cancel them right now, or restart them from where I paused them.
With explicitely coded FSM, you can do any of this, easily.