Class: LLM::Function::Async::Group

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

Overview

Wraps an array of Task objects running on a shared Reactor. The reactor is created on demand if not provided.

Instance Method Summary collapse

Constructor Details

#initialize(tasks, options = {}) ⇒ Group

Returns a new instance of Group.

Parameters:

Options Hash (options):



13
14
15
16
# File 'lib/llm/function/async/group.rb', line 13

def initialize(tasks, options = {})
  @tasks = tasks
  @reactor = options[:reactor] || LLM::Function::Async::Reactor.new
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


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

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

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)


38
39
40
41
# File 'lib/llm/function/async/group.rb', line 38

def interrupt!
  @tasks.each(&:interrupt!)
  nil
end

#spawnnil

Returns:

  • (nil)


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

def spawn
  @tasks.each do |task|
    task.reactor = @reactor
    task.spawn
  end
  nil
ensure
  @spawned = true
end

#waitArray<LLM::Function::Return> Also known as: value



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

def wait
  spawn unless @spawned
  @tasks.map(&:wait)
ensure
  @reactor.stop
end