: Re: StructuredTaskScope and Futures
Arnaud Masson
arnaud.masson at fr.ibm.com
Thu Jan 5 13:16:14 UTC 2023
I prefer the Supplier approach a lot.
Future usage in StructuredTaskScope looks weird especially since it reintroduces async style “legacy” where we don’t expect it.
Btw has a safer lambda-oriented API been considered (as an optional static helper)? for example:
var sum = StructuredTaskScope.execute(
() -> task1(),
() -> task2(),
(result1, result2) -> result1 + result2
) // throws if any error in one of the parallel tasks
(It could be defined for 2,3,4… args)
Thanks
Arnaud
That is exactly what Supplier.get() would do. It will not block, but throw an IllegalStateException if called before the scope is joined. There is no need for it to every throw any “logic” exception, because failures would be handled collectively by the policy immediately after joining. In the ShutdownOnFailure case, you would then call get once you know the forks have succeeded. In the ShutdownOnSuccess case, you won’t use the Supplier at all (just ShutdownOnSuccess.result()).
— Ron
Unless otherwise stated above:
Compagnie IBM France
Siège Social : 17, avenue de l'Europe, 92275 Bois-Colombes Cedex
RCS Nanterre 552 118 465
Forme Sociale : S.A.S.
Capital Social : 664 069 390,60 €
SIRET : 552 118 465 03644 - Code NAF 6203Z
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230105/b428b5ec/attachment.htm>
More information about the loom-dev
mailing list