How to call wait on multiple Tasks?

Hey all, I have some code that uses @spawn to generate ~50 tasks

tasks=Vector{Task}()

function process_row_group(range::Tuple{Int64,RangeMarker})
    for col_name in col_names
        push!(tasks, Threads.@spawn process_column_cursor(col_name, range))
    end
end

I know it’s possible to call wait(task) for a single one. What the best way to wait on them all? Would foreach(wait, tasks) be the best way to do this?

    @sync for col_name in col_names
        Threads.@spawn process_column_cursor(col_name, range))
    end
2 Likes

Is there a simple way, how I can wait for one of them? I.e. when one of them has available value, I would consume it and ask it for calculating the next value.

Thanks,
Tomas

Use Channels to communicate between tasks.
https://docs.julialang.org/en/v1/manual/asynchronous-programming/

1 Like