Class: LLM::Function::Thread::Task
- Inherits:
-
LLM::Function::Task
- Object
- LLM::Function::Task
- LLM::Function::Thread::Task
- Defined in:
- lib/llm/function/thread/task.rb
Overview
LLM::Function::Thread::Task wraps a function call in a background thread for concurrent tool execution. The thread is created lazily when #wait is called, not when the task is constructed — so you can build a task, pass it around, and decide when to run it.
Interrupting a running task raises Interrupt inside
the thread, which stops the tool call mid-flight. The thread
is created with report_on_exception disabled so unhandled
exceptions propagate through #wait instead of to stderr.
Instance Attribute Summary
Attributes inherited from LLM::Function::Task
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #group_class ⇒ Class
-
#initialize(fn, options = {}) ⇒ Task
constructor
A new instance of Task.
- #interrupt! ⇒ nil (also: #cancel!)
- #spawn ⇒ nil
- #wait ⇒ LLM::Function::Return (also: #value)
Constructor Details
#initialize(fn, options = {}) ⇒ Task
Returns a new instance of Task.
19 20 21 |
# File 'lib/llm/function/thread/task.rb', line 19 def initialize(fn, = {}) super end |
Instance Method Details
#alive? ⇒ Boolean
33 34 35 |
# File 'lib/llm/function/thread/task.rb', line 33 def alive? @thread&.alive? || false end |
#group_class ⇒ Class
56 57 58 |
# File 'lib/llm/function/thread/task.rb', line 56 def group_class LLM::Function::Thread::Group end |
#interrupt! ⇒ nil Also known as: cancel!
39 40 41 42 43 |
# File 'lib/llm/function/thread/task.rb', line 39 def interrupt! @thread&.raise(LLM::Interrupt) if @thread&.alive? function.interrupt! nil end |
#spawn ⇒ nil
25 26 27 28 29 |
# File 'lib/llm/function/thread/task.rb', line 25 def spawn @thread = ::Thread.new { function.call } @thread.report_on_exception = false nil end |
#wait ⇒ LLM::Function::Return Also known as: value
48 49 50 51 |
# File 'lib/llm/function/thread/task.rb', line 48 def wait spawn unless @thread @thread.value end |