|
|
|
|
|
by Jtsummers
1370 days ago
|
|
The pattern in the example above is a fork/join model of concurrency. Task.async will spawn a new task and return a handle to it, the task will be scheduled and run at some point. Task.await takes that handle and waits for the associated task to complete before continuing and returns its result. do_work = Task.async(fn -> long_calculation() end)
That kicks off the new task, at some point later we should obtain and examine the result: result = Task.await(do_work)
https://hexdocs.pm/elixir/1.13/Task.html#await/2 |
|
But why would anybody "kick off a task without the await part"?