Class: LLM::Function::ThreadGroup
- Inherits:
-
Object
- Object
- LLM::Function::ThreadGroup
- Defined in:
- lib/llm/function/thread_group.rb
Overview
The ThreadGroup class wraps an array of
Thread objects that are running LLM::Function calls
concurrently. It provides a single #wait method that
collects the Return values from those
threads.
This class is returned by Array#spawn
when you call ctx.functions.spawn on the collection
returned by Context#functions. It is a lightweight
wrapper that does not inherit from Ruby's built-in
ThreadGroup.
Instance Method Summary collapse
-
#initialize(threads) ⇒ LLM::Function::ThreadGroup
constructor
Creates a new ThreadGroup from an array of
Threadobjects. -
#alive? ⇒ Boolean
Returns whether any thread in the group is still alive.
- #interrupt! ⇒ nil (also: #cancel!)
-
#wait ⇒ Array<LLM::Function::Return>
(also: #value)
Waits for all threads in the group to finish and returns their Return values.
Constructor Details
#initialize(threads) ⇒ LLM::Function::ThreadGroup
Creates a new LLM::Function::ThreadGroup from an array
of Thread objects.
39 40 41 |
# File 'lib/llm/function/thread_group.rb', line 39 def initialize(threads) @threads = threads end |
Instance Method Details
#alive? ⇒ Boolean
Returns whether any thread in the group is still alive.
This method checks if any of the threads in the group are still running. It can be useful for monitoring concurrent tool execution without blocking.
64 65 66 |
# File 'lib/llm/function/thread_group.rb', line 64 def alive? @threads.any?(&:alive?) end |
#interrupt! ⇒ nil Also known as: cancel!
70 71 72 73 |
# File 'lib/llm/function/thread_group.rb', line 70 def interrupt! @threads.each(&:interrupt!) nil end |
#wait ⇒ Array<LLM::Function::Return> Also known as: value
97 98 99 |
# File 'lib/llm/function/thread_group.rb', line 97 def wait @threads.map(&:value) end |