2 ms·
async/await produces a Future. In order for that Future to execute, you place it on an executor. It won't start executing until you do so. Which thread it runs
by steveklabnik 7y ago
async/await produces a Future. In order for that Future to execute, you place it on an executor. It won't start executing until you do so. Which thread it runs on, and how, is all the executor's job. So the answer is basically "pick the executor which has the semantics you want".
- deleted 7y ago[deleted]
- hinkley 7y agoI never liked this behavior in Java. Or rather, I wasn't sure it was right or wrong and then I found code where people returned a future without starting it, causing the caller to wait forever in some situations. Also if you use multiple modules with their own executors, they don't compose well. You can easily get oversubscription of CPUs. Javascript's promises are self starting, which I would say is an improvement but the total lack of back pressure is anywhere from galling to highly problematic depending on the problem domain. Goldilocks solution might be to have default executor behavior with an obvious and straightforward way to override it.