Class: LLM::Function::Async::Reactor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeReactor

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

#threadThread (readonly)

Returns:



11
12
13
# File 'lib/llm/function/async/reactor.rb', line 11

def thread
  @thread
end

Instance Method Details

#stopObject

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.

Returns:

  • (nil)


21
22
23
24
# File 'lib/llm/function/async/reactor.rb', line 21

def submit(&block)
  @inbox << block
  nil
end