Class: LLM::Function::Sequential::Group

Inherits:
Group
  • Object
show all
Defined in:
lib/llm/function/sequential/group.rb

Overview

Wraps an array of Task objects for sequential execution. Provides the same interface as concurrent group wrappers so callers can flow through task(strategy).wait regardless of the strategy being used.

Instance Method Summary collapse

Constructor Details

#initialize(tasks) ⇒ LLM::Function::Sequential::Group

Parameters:



15
16
17
18
# File 'lib/llm/function/sequential/group.rb', line 15

def initialize(tasks)
  @tasks = tasks
  @owner = nil
end

Instance Method Details

#spawn ⇒ nil

Returns:

  • (nil)


22
23
24
25
26
27
28
# File 'lib/llm/function/sequential/group.rb', line 22

def spawn
  # no-op (execution happens in wait)
  @tasks.each(&:spawn)
  nil
ensure
  @spawned = true
end

#alive? ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/llm/function/sequential/group.rb', line 32

def alive?
  @tasks.any?(&:alive?)
end

#interrupt! ⇒ nil Also known as: cancel!

Interrupts the thread blocked in #wait, and tells the tasks.

Sequential functions run on the caller's thread, so the raise is what interrupts the call and it has to land there. It is issued first, and the tasks are told second: the delivery is this group's whole interrupt, and a hook that raises must not be able to take it with it or to leave the remaining tasks untold. That is also the order the in-process strategies use, where the hook runs after the raise.

Returns:

  • (nil)


46
47
48
49
50
# File 'lib/llm/function/sequential/group.rb', line 46

def interrupt!
  @owner&.raise(LLM::Interrupt)
  @tasks.each(&:interrupt!)
  nil
end

#wait ⇒ Array<LLM::Function::Return> Also known as: value

Returns:

See Also:



56
57
58
59
60
61
# File 'lib/llm/function/sequential/group.rb', line 56

def wait
  @owner = Thread.current
  super
ensure
  @owner = nil
end