Batch v0.2.0 Batch.Supervisor View Source
A batch supervisor.
This module defines a supervisor which can be used to dynamically supervise batches.
start_link/1 can be used to start the supervisor. See the Batch module for more
examples.
Name registration
A Batch.Supervisor is bound to the same name registration rules as a GenServer.
Read more about them in the GenServer docs.
Link to this section Summary
Functions
Starts a batch that can be awaited on
Starts a batch that can be awaited on
Returns all children PIDs
Starts a batch as a child of the given supervisor
Starts a new supervisor
Terminates the child with the given pid
Link to this section Types
option :: Supervisor.option | {:restart, :supervisor.restart} | {:shutdown, :supervisor.shutdown}
Option values used by start_link
Link to this section Functions
async(Supervisor.supervisor, [function | mfa]) :: Batch.t
Starts a batch that can be awaited on.
The supervisor must be a reference as defined in Batch.Supervisor. The batch will still
be linked to the caller, see Batch.async/1 for more information and async_nolink/2 for a
non-linked variant.
Note this function requires the batch supervisor to have :temporary as the :restart
option (the default), as async/2 keeps a direct reference to the batch which is
lost if the batch is restarted.
async_nolink(Supervisor.supervisor, [function | mfa]) :: Batch.t
Starts a batch that can be awaited on.
The supervisor must be a reference as defined in Batch.Supervisor. The batch won’t be
linked to the caller, see Batch.async/1 for more information.
Note this function requires the batch supervisor to have :temporary as the :restart
option (the default), as async_nolink/2 keeps a direct reference to the batch which
is lost if the batch is restarted.
Compatibility with OTP behaviours
If you create a batch using async_nolink inside an OTP behaviour like GenServer, you
should match on the message coming from the batch inside your GenServer.handle_info/2
callback.
The reply sent by the batch will be in the format {ref, result}, where ref is the
monitor reference held by the batch struct and result is the return value of the batch
functions.
Keep in mind that, regardless of how the batch created with async_nolink terminates, the
caller’s process will always receive a :DOWN message with the same ref value that is
held by the batch struct. If the batch terminates normally, the reason in the :DOWN
message will be :normal.
Returns all children PIDs.
start_child(Supervisor.supervisor, [function | mfa]) :: {:ok, pid}
Starts a batch as a child of the given supervisor.
Note that the spawned process is not linked to the caller, but only to the supervisor. This command is useful in case the batch needs to perform side-effects (like I/O) and does not need to report back to the caller.
start_link([option]) :: Supervisor.on_start
Starts a new supervisor.
The supported options are:
:name- used to register a supervisor name, the supported values are described under theName Registrationsection in theGenServermodule docs;:restart- the restart strategy, may be:temporary(the default),:transientor:permanent.:temporarymeans the batch is never restarted,:transientmeans it is restarted if the exit is not:normal,:shutdownor{:shutdown, reason}. A:permanentrestart strategy means it is always restarted. It defaults to:temporaryso batches aren’t automatically restarted when they complete nor in case of crashes. Note the:asyncfunctions in this module support only:temporaryrestarts;:shutdown-:brutal_killif the batch must be killed directly on shutdown or an integer indicating the timeout value, defaults to 5000 milliseconds;:max_restartsand:max_seconds- as specified inSupervisor;
terminate_child(Supervisor.supervisor, pid) :: :ok
Terminates the child with the given pid.