View Source Runbox.Scenario.Helper (runbox v13.0.3)
Support for helper processes for scenarios.
Provides a supervisor and process registry under which scenarios can start their side-kick processes intended for housekeeping tasks.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a supervisor with dynamic supervisor and process registry.
Returns a :via
name to be used in the helper process registry.
Executes a given callback
over running helper.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_link(any()) :: Supervisor.on_start()
Starts a supervisor with dynamic supervisor and process registry.
Returns a :via
name to be used in the helper process registry.
@spec with_helper(any(), child_spec, (pid() -> any())) :: any() when child_spec: :supervisor.child_spec() | {module(), term()} | module()
Executes a given callback
over running helper.
Checks whether the helper with name
registered under helper registry is
already running. If not, then it starts the process according to child_spec
under the dynamic supervisor. In either case, it passes the helper process
pid to the callback
.
It is the responsibility of the helper process to register its name with the
helper registry via the via_registry/1
.
Examples
iex> child_spec = %{
...> id: MyHelper,
...> start: {
...> Agent,
...> :start_link,
...> [fn -> 1 end, [name: Helper.via_registry(MyHelper)]]
...> }
...> }
iex> :ok = Helper.with_helper(MyHelper, child_spec, fn pid -> Agent.update(pid, & &1 + 1) end)
iex> Helper.with_helper(MyHelper, child_spec, fn pid -> Agent.get(pid, & &1) end)
2