For your consideration on exposing continuations as API
Alan Bateman
Alan.Bateman at oracle.com
Thu Nov 12 09:10:47 UTC 2020
On 11/11/2020 20:30, Pedro Lamarão wrote:
> [Sorry for reposting: I used the wrong sender last time.]
>
> Hello all!
> Thank you very much for your work on this project!
>
> I am aware the current intention is that continuations are not public API.
> I am sending this message as a case for exposing continuations as API.
>
> My paid work is mainly about data pipelines.
> I have experimented with using continuations to design "continuable"
> parsers.
> Such things usually require state machines.
>
> Below is a link to one of these experiments, a simple BER parser.
> Please don't mind my ressignification of "push" in this context.
> https://github.com/pedrolamarao/loom/blob/main/ber/src/main/java/loom
> /ber/DerPushParser.java
>
> In my experience, operators like the above are very easy to compose, while
> InputStream consumers are not.
> I was able to produce this code with a few hours reading "The State of Loom",
> javadoc and writing code.
>
> I hope a strong case can be made for exposing continuations to the public
> in future releases!
>
I think you are asking for generators which are indeed easy to do with
continuations. I think there are others on this mailing list that have
been experimenting with them too. There isn't any concrete proposals for
generators right now but it an area to explore further (so having
examples like your parser is good).
There are several concerns with exposing continuations. The Java
Language is intended to be approachable by average developers so
exposing a new form control flow would be a challenge. From a technical
perspective, the main issue is that it can lead to
Thread.currentThread() changing its value in the same thread of
execution. This arises if you yield and then run/continue on a different
thread. Locks, thread locals, and anything else that depends on the
current Thread identity breaks. There have been suggestions that
continuations should be thread confined but that might be too limiting
for the advanced group.
-Alan
More information about the loom-dev
mailing list