TermUI.Command.Executor (TermUI v0.2.0)

View Source

Executes commands asynchronously under a Task.Supervisor.

The executor runs commands in isolated tasks, preventing failures from crashing the runtime. Results are sent back as messages to the originating component.

Usage

# Start the executor (usually in application supervision tree)
{:ok, executor} = Executor.start_link()

# Execute a command
{:ok, command_id} = Executor.execute(executor, command, runtime_pid, component_id)

# Cancel a running command
:ok = Executor.cancel(executor, command_id)

Summary

Functions

Cancels a running command by ID.

Cancels all commands for a component.

Returns a specification to start this module under a supervisor.

Executes a command asynchronously.

Returns the number of currently running commands.

Starts the command executor.

Types

t()

@type t() :: pid()

Functions

cancel(executor, command_id)

@spec cancel(t(), reference()) :: :ok | {:error, :not_found}

Cancels a running command by ID.

cancel_all_for_component(executor, component_id)

@spec cancel_all_for_component(t(), atom()) :: :ok

Cancels all commands for a component.

Used when a component unmounts.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

execute(executor, command, runtime_pid, component_id)

@spec execute(t(), TermUI.Command.t(), pid(), atom()) ::
  {:ok, reference()} | {:error, term()}

Executes a command asynchronously.

Returns the command ID that can be used for cancellation. Results are sent to the runtime as {:command_result, component_id, command_id, result}.

running_count(executor)

@spec running_count(t()) :: non_neg_integer()

Returns the number of currently running commands.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the command executor.

Options

  • :name - GenServer name (optional)
  • :max_concurrent - Maximum concurrent commands (default: 100)