3 ms·
> Even at CPU level, "sequential" instructions aren't Within the context of the argument you are making, this is disingenuous. There's a big pile of transisto
by cellularmitosis 7y ago
> Even at CPU level, "sequential" instructions aren't
Within the context of the argument you are making, this is disingenuous. There's a big pile of transistors which determine whether it is safe to reorder those instructions.
- nine_k 7y agoThar same pile of transistors, with a thick layer of software, determines whether it's safe to proceed a coroutine. const foo = async () { const ice = await freeze(water); const wCream = await whip(cream); const base = await pour(liquor, ice); const cocktail = await put(base, wCream); return cocktail.serve(); } In the above fragment, `freeze` and `whip` may run in any order or in parallel, you don't get to choose. Still `pour` never runs before `freeze` (though it can complete before `whip`), and `put` can only run last. This is because the above is syntactic sugar, and the dataflow graph gets encoded in the promises graph, with `.then` clauses giving an unequivocal dependency order where applicable. Same in CPU: two loads can run in either order or in parallel, but an ADD that takes the result of both of them will only run when they both complete.
- esprehn 7y agoIs there a bug in your example? You await freeze before calling whip. They can't run in any order or in parallel and must complete sequentially. pour also cannot complete before whip since whip is being awaited. That example is: const foo = async () => freeze(water) .then(ice => whip(cream) .then(wCream => pour(liquor, ice) .then(base => put(base, cream) .then(cocktail => cocktail.serve()))));
- nine_k 7y agoThanks. I stand corrected.
- derangedHorse 7y agoMaybe there’s a misunderstanding with how async/await works...
- nine_k 7y agoApparently so — thank you!