Structured Concurrency yet again

forax at univ-mlv.fr forax at univ-mlv.fr
Tue May 9 17:29:57 UTC 2023


----- Original Message -----
> From: "attila kelemen85" <attila.kelemen85 at gmail.com>
> To: "Pedro Lamarão" <pedro.lamarao at prodist.com.br>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "loom-dev" <loom-dev at openjdk.java.net>
> Sent: Tuesday, May 9, 2023 7:16:04 PM
> Subject: Re: Structured Concurrency yet again

> Pedro Lamarão <pedro.lamarao at prodist.com.br> ezt írta (időpont: 2023.
> máj. 9., K, 19:11):
>>
>> Em ter., 9 de mai. de 2023 às 13:35, Remi Forax <forax at univ-mlv.fr> escreveu:
>>
>>>
>>> If we put everything together, we get the following code
>>>
>>>   try(var scope = new AsyncScope<Integer, RuntimeException>()) {
>>>       AsyncTask<Integer, RuntimeException> task = scope.async(() -> {
>>>           Thread.sleep(100);
>>>           return 10;
>>>       });
>>>       var task2 = scope.async(() -> {
>>>           Thread.sleep(300);
>>>           return 30;
>>>       });
>>
>>
>>
>> How would we use AsyncScope to concurrently call two services which return
>> different data types?
>>
> 
> Previously the scope took a generic parameter "T", and then the fork
> call returned <R extends T>, so you could declare T to be Object, and
> then do whatever.

yes, the scope is declared with the common super type of the two data types, by example,

   try(var scope = new AsyncScope<Object, RuntimeException>()) {
       AsyncTask<String, RuntimeException> task = scope.async(() -> {
           Thread.sleep(100);
           return "foo";
       });
       AsyncTask<Integer, RuntimeException>  task2 = scope.async(() -> {
           Thread.sleep(300);
           return 30;
       });
       ...

regards,
Rémi




More information about the loom-dev mailing list