Tasks
Extends spawn to provide better error & introspection
Meant to execute on task with little communication, like turning seq code into async to compute values/send requests
Methods Overview
Task.start/1
Task.start_link/1
Task.async/1
- expects reply that is always sent (will crash if caller crashes)Task.await/1
Sequential => Concurrent Code
Adhoc Tasks
Can easily run without a supervisor for unessential tasks like emails
Async requests
Task Supervisor
Summary:
Use
Task.Supervisor.start_child/2
to start a fire-and-forget task and you don't care about its results nor about if it completes successfullyUse
Task.Supervisor.async/2
+Task.await/2
allows you to execute tasks concurrently and retrieve its result. If the task fails, the caller will also failUse
Task.Supervisor.async_nolink/2
+Task.yield/2
+Task.shutdown/2
allows you to execute tasks concurrently and retrieve their results or the reason they failed within a given time frame. If the task fails, the caller won't fail: you will receive the error reason either onyield
orshutdown
Setup
Application.ex
Somewhere in app
account_setup.ex
Tasks will be run with when that ft
Your CRM sample
Last updated