defmodule Runbox.RunStartContext do @moduledoc """ Structure holding context of starting run. This structure is passed as param to every run component start. """ defstruct components_pids: %{} @typedoc """ Currently context holds only mapping of names to pids of already started components. """ @type t :: %__MODULE__{components_pids: %{term => pid}} @doc """ Adds pid of component identified by `name` to context. """ @spec add_component(t, term, pid) :: t def add_component(ctx, name, pid) do %__MODULE__{ctx | components_pids: Map.put(ctx.components_pids, name, pid)} end @doc """ Returns pid of component identitfied by `name`. """ @spec component_pid(t, term) :: pid def component_pid(ctx, name) do Map.fetch!(ctx.components_pids, name) end end