Rho.ToolRegistry.Source behaviour (rho v0.1.0)

Copy Markdown View Source

A source of tools the registry asks on every call, for tool sets that change while the app runs (the Dyn layer's generations, Rho.Dyn.Source: tools the agent writes, compiles and activates on the device). Configure with {Rho.Supervisor, tool_sources: [MySource]} or config :rho, :tool_sources, [MySource].

tools/0 and lookup/1 run in the caller's process (the loop, at the start of every model call) and must be cheap: read an ETS table or a persistent term, don't call a process that may be busy.

Summary

Callbacks

The source's current tool named name.

The source's current tools as {name, module}.

A call of module (any tool, not only this source's) is about to run in the task pid: a source that keeps its tools on probation can monitor it. Runs in that task, before the tool; it must return quickly.

Callbacks

lookup(name)

@callback lookup(name :: String.t()) :: {:ok, module()} | :error

The source's current tool named name.

tools()

@callback tools() :: [{String.t(), module()}]

The source's current tools as {name, module}.

watch(pid, module)

(optional)
@callback watch(pid(), module()) :: :ok

A call of module (any tool, not only this source's) is about to run in the task pid: a source that keeps its tools on probation can monitor it. Runs in that task, before the tool; it must return quickly.