Is there a version of @sync that throws error when the task failed?

By default, @sync will collect all the exceptions in its block and throw them after everything is done. However, I have a code looking like

@sync begin
    @async for i in 1:1000
          # task A
     end
    @async for i in 1:1000
          # task B
    end
end

In my case, if task B failed, task A will be blocked and @sync will wait for ever.

Is there a version of @sync such that an exception is immediately thrown if one of the task it encloses failed?

Have you tried catching the exception in task B and using that information to end task A? Sync by default can’t do this unless you use wait on task B, which is another option.

2 Likes