Module: Textus::Produce::Engine::AsyncRunner

Defined in:
lib/textus/produce/engine.rb

Overview

In-process deferral for the async write trigger (ADR 0087/0093). Spawns a tracked thread that runs Produce.converge after the write returns; a one-time at_exit joins all pending threads so a short-lived CLI process cannot exit before an async rebuild completes. The write itself never blocks.

Class Method Summary collapse

Class Method Details

.drainObject

Block until every spawned async rebuild has finished. Idempotent; safe to call from at_exit and directly from tests.



114
115
116
117
118
119
# File 'lib/textus/produce/engine.rb', line 114

def drain
  pending = @mutex.synchronize { @threads.dup }
  pending.each(&:join)
  @mutex.synchronize { @threads.delete_if { |t| !t.alive? } }
  nil
end

.enqueue(container:, call:, keys:) ⇒ Object



106
107
108
109
110
# File 'lib/textus/produce/engine.rb', line 106

def enqueue(container:, call:, keys:)
  thread = Thread.new { Textus::Produce::Engine.converge(container: container, call: call, keys: keys) }
  track(thread)
  thread
end