[External] : API proposal for StructuredTaskScope

Ron Pressler ron.pressler at oracle.com
Fri Jan 6 19:38:09 UTC 2023


On 5 Jan 2023, at 15:22, forax at univ-mlv.fr<mailto:forax at univ-mlv.fr> wrote:

----- Original Message -----
From: "Ron Pressler" <ron.pressler at oracle.com<mailto:ron.pressler at oracle.com>>
To: "Remi Forax" <forax at univ-mlv.fr<mailto:forax at univ-mlv.fr>>
Cc: "loom-dev" <loom-dev at openjdk.java.net<mailto:loom-dev at openjdk.java.net>>
Sent: Thursday, January 5, 2023 3:37:06 PM
Subject: Re: [External] : API proposal for StructuredTaskScope

We have considered such approaches.

One glaring problem is the case of “heterogenous tasks”, i.e. tasks that each
return a result of a different type. This is a very common scenario for
ShutdownOnFailure.

I believe that using a static factory instead of a constructor (here StructuredTaskScope.of()) solve that pretty well.
If no type is explicitly provided, the inference will default to Object which is exactly what you want in case of a shutdown on failure.

I don’t follow. The scenario I had in mind is this:

Response handle() throws ExecutionException, InterruptedException {
    try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
        Future<String>  s1  = scope.fork(() -> fetchS1());
        Future<String>  s2  = scope.fork(() -> fetchS2());
        Future<Integer> i1  = scope.fork(() -> fetchI1());
        Future<Integer> i2  = scope.fork(() -> fetchI2());

        scope.join().throwIfFailed();

        return new Response(s1, s2, i1, i2);
    }
}

How do you propose to do it when fork returns void?

— Ron

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230106/83764e5d/attachment.htm>


More information about the loom-dev mailing list