@@ -56,28 +56,27 @@ defmodule Task do
56
56
57
57
## Supervised tasks
58
58
59
- It is also possible to spawn a task under a supervisor
60
- with `start_link/1` and `start_link/3`:
61
-
62
- Task.start_link(fn -> IO.puts "ok" end)
63
-
64
- Such tasks can be mounted in your supervision tree as:
59
+ It is also possible to spawn a task under a supervisor:
65
60
66
61
import Supervisor.Spec
67
62
68
63
children = [
64
+ #
69
65
worker(Task, [fn -> IO.puts "ok" end])
70
66
]
71
67
68
+ Internally the supervisor will invoke `Task.start_link/1`.
69
+
72
70
Since these tasks are supervised and not directly linked to
73
71
the caller, they cannot be awaited on. Note `start_link/1`,
74
72
unlike `async/1`, returns `{:ok, pid}` (which is
75
73
the result expected by supervision trees).
76
74
77
75
By default, most supervision strategies will try to restart
78
- a worker after it exits regardless of the reason. If you design the
79
- task to terminate normally (as in the example with `IO.puts/2` above),
80
- consider passing `restart: :transient` in the options to `Supervisor.Spec.worker/3`.
76
+ a worker after it exits regardless of the reason. If you design
77
+ the task to terminate normally (as in the example with `IO.puts/2`
78
+ above), consider passing `restart: :transient` in the options
79
+ to `Supervisor.Spec.worker/3`.
81
80
82
81
## Dynamically supervised tasks
83
82
0 commit comments