Condukt.Park (Condukt v3.0.0)

Copy Markdown View Source

How a tool call waits for an outside event or a time.

A tool parks by returning {:park, state, opts} from Condukt.Tool.call/2 instead of a result, much as a GenServer callback returns {:noreply, state, timeout}:

{:park, %{build_id: build.id},
 signals: [{MyApp.Signals.CiResult, "ci-" <> context.tool_call_id}],
 timeout: :timer.hours(2)}

Options:

  • :signals - {kind, key} pairs to wake on, where kind is a Condukt.Signal module and key a string. The first one delivered wakes the call.
  • :timeout - milliseconds from now after which the call wakes anyway.
  • :until - a DateTime after which the call wakes anyway. Use either :until or :timeout, not both.

A park needs signals, a deadline, or both, and the tool must implement Condukt.Tool.wake/3. While a call is parked no tool code runs: the turn's worker blocks in receive, the tool timeout does not apply, and the session holds the wait as data. When the call wakes, the session calls wake/3 with {:signal, {kind, key}, value} or :timeout, and state.

The deadline is stored as wall-clock time rather than as a timer, so it means the same thing after the session process that armed it is gone. A running session arms it with Process.send_after/3.

See the Waiting for Events guide.

Summary

Functions

Validates park options, returning {:ok, park} or {:error, reason}.

Functions

new(opts)

Validates park options, returning {:ok, park} or {:error, reason}.

until in the result is a Unix time in milliseconds, or nil.