It’s solved in stackoverflow
All the answer from @Przemyslaw Szufel, I just sum it up as a note:
@sync for loop do task A
@async do task(a)
do task(B)
then Task B will wait until Task A finishes. And Multi Task a in Task A will be async to each other.
It is the building block for do multi Task a and then do Task B.
if you want to nest it, then just:
@sync for loop do Task (A,B)
@async begin
@sync for loop do task A
@async do task(a)
do task(B)
end
do task C
use the @sync macro before the for loop and then use the @async macro to wrap the content in the for loop. Then the multi little tasks in the for loop will run async to each other, but the code after the for loop will wait until the for loop finishes.
example code from @Przemyslaw Szufel
function do_task(t, x)
println("start $t : $x")
flush(stdout)
sleep(1 / x)
println("Done $t : $x")
flush(stdout)
end
@time @sync for (A, B) in [([1, 2], 100), ([3, 4], 101), ([5, 6], 102)]
@async begin
@sync for a in A
@async do_task(:A, a)
end
do_task(:B, B)
end
end