Class: LLM::Function::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/function/task.rb

Overview

The Task class wraps a single concurrent function call and provides a small, uniform interface across threads, fibers, and async tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, function = nil) ⇒ LLM::Function::Task

Parameters:

  • task (Thread, Fiber, Async::Task)
  • function (LLM::Function, nil) (defaults to: nil)


20
21
22
23
# File 'lib/llm/function/task.rb', line 20

def initialize(task, function = nil)
  @task = task
  @function = function
end

Instance Attribute Details

#taskObject (readonly)

Returns:



10
11
12
# File 'lib/llm/function/task.rb', line 10

def task
  @task
end

#functionLLM::Function? (readonly)

Returns:



14
15
16
# File 'lib/llm/function/task.rb', line 14

def function
  @function
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/llm/function/task.rb', line 27

def alive?
  task.alive?
end

#waitLLM::Function::Return Also known as: value



33
34
35
36
37
38
39
40
41
42
# File 'lib/llm/function/task.rb', line 33

def wait
  if Thread === task
    task.value
  elsif Fiber === task
    task.resume if task.alive?
    task.value
  else
    task.wait
  end
end