class RatatuiRuby::Tea::Command::CancellationToken

Cooperative cancellation mechanism for long-running commands.

Long-running commands block the event loop. Commands that poll, stream, or wait indefinitely prevent clean shutdown. Killing threads mid-operation corrupts state.

This class signals cancellation requests. Commands check cancelled? periodically and stop gracefully. The runtime calls cancel! when shutdown begins.

Use it to implement WebSocket handlers, database pollers, or any command that loops.

Example

class PollerCommand
  include Tea::Command::Custom

  def call(out, token)
    until token.cancelled?
      data = fetch_batch
      out.put(:batch, data)
      sleep 5
    end
    out.put(:poller_stopped)
  end
end