Structured Concurrency API ?

Ron Pressler ron.pressler at oracle.com
Fri Apr 8 19:38:31 UTC 2022



> On 8 Apr 2022, at 20:14, Ron Pressler <ron.pressler at oracle.com> wrote:
> 
> I have been toying with a different idea for functional composition of structured concurrency.
> 
>    Stream.of(“abc”, “cde”, “efg”).__threads().filter(s -> s.contains(“c”)).findAny()
> 
> where __threads() will spawn a new thread for each element in the stream, the filter operation will run concurrently in each of the threads, and findAny(), will shutdown all remaning threads after finding an element (limit() would behave analogously). Operations that require order will join all the threads (or as many of them as necessary, to ensure that findFirst() would return “abc” and not “cde”), but we could also have an explicit join() method to continue the rest of the pipeline on the curren thread. Of course, relevant operations will probably include some blocking IO.
> 
> — Ron

P.S.

Overrides of __threads can take a ThreadFactory and/or a timeout.

I have a working prototype, but the design is still in its infancy. The proposed StructuredTaskScope API is not intended to be the last word on structured concurrency; indeed, it is only the first.



More information about the loom-dev mailing list