Class: LLM::Function::Task
- Inherits:
-
Object
- Object
- LLM::Function::Task
- 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, scheduler-backed fibers, and async tasks.
Instance Attribute Summary collapse
- #task ⇒ Object readonly
- #function ⇒ LLM::Function? readonly
Instance Method Summary collapse
- #initialize(task, function = nil) ⇒ LLM::Function::Task constructor
- #alive? ⇒ Boolean
- #interrupt! ⇒ nil (also: #cancel!)
- #wait ⇒ LLM::Function::Return (also: #value)
Constructor Details
#initialize(task, function = nil) ⇒ LLM::Function::Task
21 22 23 24 |
# File 'lib/llm/function/task.rb', line 21 def initialize(task, function = nil) @task = task @function = function end |
Instance Attribute Details
#function ⇒ LLM::Function? (readonly)
15 16 17 |
# File 'lib/llm/function/task.rb', line 15 def function @function end |
Instance Method Details
#alive? ⇒ Boolean
28 29 30 31 |
# File 'lib/llm/function/task.rb', line 28 def alive? return task.alive? if task.respond_to?(:alive?) false end |
#interrupt! ⇒ nil Also known as: cancel!
35 36 37 38 |
# File 'lib/llm/function/task.rb', line 35 def interrupt! function&.interrupt! nil end |
#wait ⇒ LLM::Function::Return Also known as: value
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/llm/function/task.rb', line 43 def wait if Thread === task task.value elsif Fiber === task fiber.alive? ? scheduler.run : nil task.value else task.wait end end |