News for hackers. Stuff that matters.
Re:V8 adds support for top-level await by nine_k on Tuesday September 24, 2019 @08:28PM (#21066285)
I think it's worth stopping to think in terms of "sequential lines of code". Even at CPU level, "sequential" instructions aren't, for a decade or so, to say nothing of xplicitly async code.

One should think in terms of a dataflow graph, where data-independent nodes can run in any order, or in parallel. One should explicitly think about ordering of effects, and be explicit about effects in general. (Hence the rise of popularity of FP.)

Re:V8 adds support for top-level await by cellularmitosis on Tuesday September 24, 2019 @11:17PM (#21067272)
> 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.

Re:V8 adds support for top-level await by nine_k on Wednesday September 25, 2019 @12:20AM (#21067566)
Thar 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.

Re:V8 adds support for top-level await by esprehn on Wednesday September 25, 2019 @12:45AM (#21067676)
Is 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()))));
Re:V8 adds support for top-level await by nine_k on Wednesday September 25, 2019 @10:29AM (#21071106)
Thanks. I stand corrected.
Re:V8 adds support for top-level await by derangedHorse on Wednesday September 25, 2019 @08:57AM (#21070278)
Maybe there’s a misunderstanding with how async/await works...
Re:V8 adds support for top-level await by nine_k on Wednesday September 25, 2019 @10:31AM (#21071128)
Apparently so — thank you!
Re:V8 adds support for top-level await by chrisweekly on Tuesday September 24, 2019 @08:59PM (#21066493)
>"be explicit about effects in general. (Hence the rise of popularity of FP.)"

Yes - the benefits of pure functions in particular are increasingly evident.