I’d like to have two simple tasks, that would symmetrically send values to each other.
function task1(other_task) res1 = send_to_other_task(other_task, 10) # switch to task2 and blocks until it sends a value @show res1 res2 = send_to_other_task(other_task, 15) @show res2 end function task2(other_task, starting_value) @show starting_value result1 = send_to_other_task(other_task, 100) @show result1 end julia> launch_communicating_tasks(task1, task2) starting_value = 10 res1 = 100 result1 = 15 res2 = :end_of_task # or somesuch flag value
How should I implement that? I tried
yieldto (both of which don’t seem to handle other-task exceptions natively, so it’s pretty rough going?), having two channels (but channels can switch on IO, which is definitely not what I’m going for, and they don’t really block the way I want?) Having a single one-value channel, and using a closed-over ref to pass values the other way around…
But well, the code is never behaving as I’d expect, and I get a hung REPL all the time… Can anyone give some high-level pointers? I’m sure I can figure out the details, but the docs are pretty sparse.