Class: Charming::Tasks::InlineExecutor
- Inherits:
-
Object
- Object
- Charming::Tasks::InlineExecutor
- Defined in:
- lib/charming/tasks/inline_executor.rb
Overview
InlineExecutor runs submitted tasks synchronously on the calling thread, pushing the resulting TaskEvent directly into the runtime’s queue. Used for testing and for environments where spawning background threads is undesirable.
Instance Method Summary collapse
-
#cancel(name) ⇒ Object
No-op: inline tasks have always finished by the time cancel could be called.
-
#initialize(queue) ⇒ InlineExecutor
constructor
queue is the thread-safe Queue (typically ‘runtime.@task_queue`) into which completed TaskEvents are pushed.
-
#shutdown(timeout: 0.0) ⇒ Object
No-op stub for the shutdown contract; nothing to join since tasks run on the caller.
-
#submit(name, timeout: nil, &block) ⇒ Object
Wraps block in a Task, invokes it immediately, and pushes the resulting TaskEvent (value or error) onto the queue.
Constructor Details
#initialize(queue) ⇒ InlineExecutor
queue is the thread-safe Queue (typically ‘runtime.@task_queue`) into which completed TaskEvents are pushed.
11 12 13 |
# File 'lib/charming/tasks/inline_executor.rb', line 11 def initialize(queue) @queue = queue end |
Instance Method Details
#cancel(name) ⇒ Object
No-op: inline tasks have always finished by the time cancel could be called.
26 27 |
# File 'lib/charming/tasks/inline_executor.rb', line 26 def cancel(name) end |
#shutdown(timeout: 0.0) ⇒ Object
No-op stub for the shutdown contract; nothing to join since tasks run on the caller.
30 31 |
# File 'lib/charming/tasks/inline_executor.rb', line 30 def shutdown(timeout: 0.0) end |
#submit(name, timeout: nil, &block) ⇒ Object
Wraps block in a Task, invokes it immediately, and pushes the resulting TaskEvent (value or error) onto the queue. Blocks that accept an argument receive a Progress reporter (its events are queued before the completion event). Returns nil.
19 20 21 22 23 |
# File 'lib/charming/tasks/inline_executor.rb', line 19 def submit(name, timeout: nil, &block) task = Task.new(name: name.to_sym, block: block, timeout: timeout) @queue << run(task) nil end |