Class: LLM::Function::Fiber::Group
- Defined in:
- lib/llm/function/fiber/group.rb
Overview
Wraps an array of Task objects for cooperative concurrent execution. Interrupts all tasks and waits for them to complete.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(tasks) ⇒ Group
constructor
A new instance of Group.
- #interrupt! ⇒ nil (also: #cancel!)
- #spawn ⇒ nil
- #wait ⇒ Array<LLM::Function::Return> (also: #value)
Constructor Details
#initialize(tasks) ⇒ Group
Returns a new instance of Group.
11 12 13 |
# File 'lib/llm/function/fiber/group.rb', line 11 def initialize(tasks) @tasks = tasks end |
Instance Method Details
#alive? ⇒ Boolean
26 27 28 |
# File 'lib/llm/function/fiber/group.rb', line 26 def alive? @tasks.any?(&:alive?) end |
#interrupt! ⇒ nil Also known as: cancel!
32 33 34 35 |
# File 'lib/llm/function/fiber/group.rb', line 32 def interrupt! @tasks.each(&:interrupt!) nil end |
#spawn ⇒ nil
17 18 19 20 21 22 |
# File 'lib/llm/function/fiber/group.rb', line 17 def spawn @tasks.each(&:spawn) nil ensure @spawned = true end |
#wait ⇒ Array<LLM::Function::Return> Also known as: value
40 41 42 43 |
# File 'lib/llm/function/fiber/group.rb', line 40 def wait spawn unless @spawned @tasks.map(&:wait) end |