vrod
Receive from Task.start_link?
I have something that takes a long time, so I used Task.start_link/1 in production so the user will not wait for this to complete (it’s ok if it takes a long time)
Task.start_link(fn -> do_work() end)
However, do_work is a private function and I want to test that the output is correct. Is there a way I can read the output of this? I cannot use Task.async and Task.await in production because I cannot block execution.
I think the easy solution is make do_work public, but I want to know more about processes. Is it possible to read return value?
Thanks you in advance
First Post!
ityonemo
Task.start* is for things where you don’t care about the return.
Are you testing the function return, or function side effects?
Also note that start_link will cause your processes to be linked, so be sure you’re ok with the user process dying resulting in the task being cancelled, potentially in a strange place. Otherwise, use Task.Supervisor.







