Hacker News new | past | comments | ask | show | jobs | submit login

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



OK, thank you very much!

But why would anybody "kick off a task without the await part"?


Sometimes you want something to happen, but you don’t want to block whatever you’re doing on that. Think things like sending a welcome email when someone signs up for a new account.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: