When should I use onFork?

Alan Bateman alan.bateman at oracle.com
Sun Aug 24 06:19:11 UTC 2025



On 23/08/2025 20:27, David Alayachew wrote:
> Woah, very good to know. And thus, even when the scope is closed, 
> onFork will still be called is what you are saying?
>
> Thanks for this. Very useful.
>
No, fork is specified to throw IllegalStateException if closed. My 
comment is pointing out that if you cancel the scope then the result 
from any subtasks that are still executing does not contribute to the 
outcome. Once you cancel then onComplete for these "still running (and 
interrupted)" subtasks won't be called. To put it another way, if the 
outcome from join is something derived from all subtasks that were 
forked then you'll need to implement onFork. It may be more common that 
the outcome is derived from the result/exception from a subset of the 
subtasks, in which case it will be the onComplete method that you implement.

-Alan


More information about the loom-dev mailing list