Class: Charming::Tasks::InlineExecutor

Inherits:
Object
  • Object
show all
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

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

#shutdown(timeout: 0.0) ⇒ Object

No-op stub for the shutdown contract; nothing to join since tasks run on the caller.



24
25
# File 'lib/charming/tasks/inline_executor.rb', line 24

def shutdown(timeout: 0.0)
end

#submit(name, &block) ⇒ Object

Wraps block in a Task, invokes it immediately, and pushes the resulting TaskEvent (value or error) onto the queue. Returns nil.



17
18
19
20
21
# File 'lib/charming/tasks/inline_executor.rb', line 17

def submit(name, &block)
  task = Task.new(name: name.to_sym, block: block)
  @queue << run(task)
  nil
end