Class: LLM::Function::Async::Reactor
- Inherits:
-
Object
- Object
- LLM::Function::Async::Reactor
- Defined in:
- lib/llm/function/async/reactor.rb
Overview
Manages an Async::Reactor on a background thread. Work is submitted through a thread-safe queue and run inside the reactor. The reactor and its fibers stay on one thread.
Instance Attribute Summary collapse
- #thread ⇒ Thread readonly
Instance Method Summary collapse
-
#initialize ⇒ Reactor
constructor
A new instance of Reactor.
-
#stop ⇒ Object
Stop the reactor and wait for the thread to finish.
-
#submit(&block) ⇒ nil
Submit a block to run inside the reactor.
Constructor Details
#initialize ⇒ Reactor
Returns a new instance of Reactor.
13 14 15 16 |
# File 'lib/llm/function/async/reactor.rb', line 13 def initialize @inbox = Queue.new @thread = ::Thread.new { run } end |
Instance Attribute Details
#thread ⇒ Thread (readonly)
11 12 13 |
# File 'lib/llm/function/async/reactor.rb', line 11 def thread @thread end |
Instance Method Details
#stop ⇒ Object
Stop the reactor and wait for the thread to finish.
28 29 30 31 32 |
# File 'lib/llm/function/async/reactor.rb', line 28 def stop @inbox << :stop @thread.join(5) @thread.kill if @thread.alive? end |
#submit(&block) ⇒ nil
Submit a block to run inside the reactor.
21 22 23 24 |
# File 'lib/llm/function/async/reactor.rb', line 21 def submit(&block) @inbox << block nil end |