class Rooibos::Command::Outlet
Messaging gateway for custom commands.
Custom commands run in background threads. They produce results that the main loop consumes.
Managing queues and message formats manually is tedious. It scatters queue logic across your codebase and makes mistakes easy.
This class wraps the queue with a clean API. Call put to send tagged messages. Debug mode validates Ractor-shareability.
Use it to send results from HTTP requests, WebSocket streams, or database polls.
Example (One-Shot)
Commands run in their own thread. Blocking calls work fine:
class FetchUserCommand include Rooibos::Command::Custom def initialize(user_id) @user_id = user_id end def call(out, _token) response = Net::HTTP.get(URI("https://api.example.com/users/#{@user_id}")) user = JSON.parse(response) out.put(:user_fetched, Ractor.make_shareable(user: user)) rescue => e out.put(:user_fetch_failed, error: e.message.freeze) end end
Example (Long-Running)
Commands that loop check the cancellation token:
class PollerCommand include Rooibos::Command::Custom def call(out, token) until token.canceled? data = fetch_batch out.put(:batch, Ractor.make_shareable(data)) sleep 5 end out.put(:poller_stopped) end end
Public Class Methods
Source
# File lib/rooibos/command/outlet.rb, line 85 def initialize(message_queue, lifecycle:) @message_queue = message_queue @live = lifecycle end