Class: SwarmSDK::Swarm::Executor
- Inherits:
-
Object
- Object
- SwarmSDK::Swarm::Executor
- Defined in:
- lib/swarm_sdk/swarm/executor.rb
Overview
Handles swarm execution orchestration
Extracted from Swarm#execute to reduce complexity and eliminate code duplication. The core execution loop, error handling, and cleanup logic are unified here.
Stop Mechanism
Supports hard-stop via swarm.stop using IO.pipe for thread-safe signaling:
swarm.stopwrites to pipe and sets@stop_requested- A listener task reads from the pipe (async-aware I/O)
- Listener calls
barrier.stopwithin the Async reactor - All child tasks receive
Async::Stopexception execute_in_taskcatchesAsync::Stop, sets interrupted flag, emits events
Instance Method Summary collapse
-
#initialize(swarm) ⇒ Executor
constructor
A new instance of Executor.
-
#run(prompt, wait:, logs:, has_logging:, original_fiber_storage:) ⇒ Result, Async::Task
Execute the swarm with a prompt.
Constructor Details
#initialize(swarm) ⇒ Executor
Returns a new instance of Executor.
19 20 21 22 |
# File 'lib/swarm_sdk/swarm/executor.rb', line 19 def initialize(swarm) @swarm = swarm @interrupted_result = nil end |
Instance Method Details
#run(prompt, wait:, logs:, has_logging:, original_fiber_storage:) ⇒ Result, Async::Task
Execute the swarm with a prompt
32 33 34 35 36 37 38 39 |
# File 'lib/swarm_sdk/swarm/executor.rb', line 32 def run(prompt, wait:, logs:, has_logging:, original_fiber_storage:) @original_fiber_storage = original_fiber_storage if wait run_blocking(prompt, logs: logs, has_logging: has_logging) else run_async(prompt, logs: logs, has_logging: has_logging) end end |