wormhole v1.4.3 Wormhole
Link to this section Summary
Functions
Invokes callback
in separate process and
waits for message from callback process containing callback return value
if finished successfully or
error reason if callback process failed for any reason
Invokes callback
in separate process and
waits for message from callback process containing callback return value
if finished successfully or
error reason if callback process failed for any reason
Called when an application is started
Link to this section Functions
Invokes callback
in separate process and
waits for message from callback process containing callback return value
if finished successfully or
error reason if callback process failed for any reason.
If callback
execution is not finished within specified timeout,
kills callback
process and returns error.
Default timeout is 5000 milliseconds.
User can specify timeout_ms
in options
keyword list.
By default there is no retry, but user can specify
retry_count
and backoff_ms
in options
.
Default backoff_ms
is 1000 milliseconds.
By default exceptions in callback-process are handled so that
supervisor does not generate CRUSH REPORT (when released - Exrm/Distillery).
This behavior can be overridden by setting crush_report
to true
.
Note:
- Crush report is not generated in Elixir by default.
- Letting exceptions propagate might be useful for some other applications too (e.g sentry client).
Examples:
iex> capture(fn-> :a end)
{:ok, :a}
iex> capture(fn-> raise "Something happened" end)
{:error, {:shutdown, %RuntimeError{message: "Something happened"}}}
iex> capture(fn-> throw "Something happened" end)
{:error, {:shutdown, {:throw, "Something happened"}}}
iex> capture(fn-> exit :foo end)
{:error, {:shutdown, {:exit, :foo}}}
iex> capture(fn-> Process.exit(self, :foo) end)
{:error, :foo}
iex> capture(fn-> :timer.sleep 20 end, timeout_ms: 50)
{:ok, :ok}
iex> capture(fn-> :timer.sleep :infinity end, timeout_ms: 50)
{:error, {:timeout, 50}}
iex> capture(fn-> exit :foo end, [retry_count: 3, backoff_ms: 100])
{:error, {:shutdown, {:exit, :foo}}}
Invokes callback
in separate process and
waits for message from callback process containing callback return value
if finished successfully or
error reason if callback process failed for any reason.
If callback
execution is not finished within specified timeout,
kills callback
process and returns error.
Default timeout is 5000 milliseconds.
User can specify timeout_ms
in options
keyword list.
By default there is no retry, but user can specify
retry_count
and backoff_ms
in options
.
Default backoff_ms
is 1000 milliseconds.
By default exceptions in callback-process are handled so that
supervisor does not generate CRUSH REPORT (when released - Exrm/Distillery).
This behavior can be overridden by setting crush_report
to true
.
Note:
- Crush report is not generated in Elixir by default.
- Letting exceptions propagate might be useful for some other applications too (e.g sentry client).
Examples:
iex> capture(Enum, :count, [[]])
{:ok, 0}
iex> capture(Enum, :count, [:foo]) |> elem(0)
:error
iex> capture(:timer, :sleep, [20], timeout_ms: 50)
{:ok, :ok}
iex> capture(:timer, :sleep, [:infinity], timeout_ms: 50)
{:error, {:timeout, 50}}
iex> capture(Kernel, :exit, [:foos], [retry_count: 3, backoff_ms: 100]) {:error, {:shutdown, {:exit, :foos}}}
Called when an application is started.
This function is called when an the application is started using
Application.start/2
(and functions on top of that, such as
Application.ensure_started/2
). This function should start the top-level
process of the application (which should be the top supervisor of the
application’s supervision tree if the application follows the OTP design
principles around supervision).
start_type
defines how the application is started:
:normal
- used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another mode and the application specification key:start_phases
is:undefined
.{:takeover, node}
- used if the application is distributed and is started on the current node because of a failover on the nodenode
.{:failover, node}
- used if the application is distributed and is started on the current node because of a failover on nodenode
, and the application specification key:start_phases
is not:undefined
.
start_args
are the arguments passed to the application in the :mod
specification key (e.g., mod: {MyApp, [:my_args]}
).
This function should either return {:ok, pid}
or {:ok, pid, state}
if
startup is successful. pid
should be the PID of the top supervisor. state
can be an arbitrary term, and if omitted will default to []
; if the
application is later stopped, state
is passed to the stop/1
callback (see
the documentation for the c:stop/1
callback for more information).
use Application
provides no default implementation for the start/2
callback.
Callback implementation for Application.start/2
.