Single Thread Continuation

Pedro Lamarão pedro.lamarao at prodist.com.br
Wed Jul 5 14:52:49 UTC 2023


Em qua., 5 de jul. de 2023 às 10:56, Paul Bjorkstrand <
paul.bjorkstrand at gmail.com> escreveu:


> I will bring it back to the challenge I gave to those wanting generators,
> exposed continuations, or custom schedulers for virtual threads: show why
> it is needed!
>

The main benefit of having generators is aligned to one of the most common
highlights for using virtual threads:
representing control flow directly, instead of doing state machines.
In the virtual thread case, this is all about asynchronous I/O; in the
generator case, this is all about complex data formats.
Today, in order to process complex data formats, you either parse and
generate an object for the entire data in one go (like DOM), or you parse
and generate a stream pushing elements to callbacks that require your user
to maintain a state machine (like SAX), or returning elements by
maintaining an internal state machine (like XMLReader).
Only with the last, reader-like, design, parsers are easily composable --
by doing higher level parsers that consume suppliers of elements from a
lower level parser.
But debugging these is hard, for the very same reason that debugging
state-mechine-style asynchronous I/O programs is hard -- one must somehow
follow the state transitions manually.
With generators, reader-like parsers can be written in the subroutine-style
with no loss of efficiency.

-- 
Pedro Lamarão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230705/f63ab264/attachment.htm>


More information about the loom-dev mailing list