Parent.Client (parent v0.13.0)

Copy Markdown View Source

Functions for interacting with parent's children from other processes.

All of these functions issue a call to the parent process. Therefore, they can't be used from inside the parent process. Use functions from the Parent module instead to interact with the children from within the process.

Likewise these functions can't be invoked inside the child process during its initialization. Defer interacting with the parent to GenServer.handle_continue/2, or if you're using another behaviour which doesn't support such callback, send yourself a message to safely do the post-init interaction with the parent.

If parent is configured with the registry?: true option, some query functions, such as child_pid/2 will perform an ETS lookup instead of issuing a call, so the caveats above won't apply.

Summary

Functions

child_meta(parent, child_ref)

@spec child_meta(GenServer.server(), Parent.child_ref()) ::
  {:ok, Parent.child_meta()} | :error

Client interface to Parent.child_meta/1.

If the parent is a registry, the result will be obtained from the ETS table.

child_pid(parent, child_id)

@spec child_pid(GenServer.server(), Parent.child_id()) :: {:ok, pid()} | :error

Client interface to Parent.child_pid/1.

If the parent is a registry, the result will be obtained from the ETS table.

children(parent)

@spec children(GenServer.server()) :: [Parent.child()]

Client interface to Parent.children/0.

If the parent is a registry, the result will be obtained from the ETS table.

restart_child(parent, child_ref)

@spec restart_child(GenServer.server(), Parent.child_ref()) :: :ok | :error

Client interface to Parent.restart_child/1.

return_children(parent, stopped_children)

@spec return_children(GenServer.server(), Parent.stopped_children()) :: :ok

Client interface to Parent.return_children/1.

shutdown_all(server, reason \\ :shutdown)

@spec shutdown_all(GenServer.server(), any()) :: Parent.stopped_children()

Client interface to Parent.shutdown_all/1.

shutdown_child(parent, child_ref)

@spec shutdown_child(GenServer.server(), Parent.child_ref()) ::
  {:ok, Parent.stopped_children()} | :error

Client interface to Parent.shutdown_child/1.

start_child(parent, child_spec, overrides \\ [])

Client interface to Parent.start_child/2.

update_child_meta(parent, child_ref, updater)

@spec update_child_meta(
  GenServer.server(),
  Parent.child_id(),
  (Parent.child_meta() -> Parent.child_meta())
) :: :ok | :error

Client interface to Parent.update_child_meta/2.