class Processor
Async background task processor, modeled after async-job's Inline processor.
The gospel (async-job) teaches:
- Async::Idler schedules tasks when the event loop is idle (backpressure)
- Each job runs in its own fiber (not thread)
- The returned Async::Task can be .wait'd for completion notification
- Errors are caught and logged, not re-raised
- task.defer_stop protects critical sections from interruption
This processor enables A2A's non-blocking mode (return_immediately: true). The handler can enqueue work that executes after the HTTP response is sent.
Usage:
processor = A2A::Store::Processor.new
Fire and forget:
processor.call store.update_state(task_id, "WORKING"); do_work; store.complete(task_id, result)
Wait for completion:
task = processor.call do_work
task.wait
Definitions
def call(&block)
Execute a block asynchronously in a background fiber.
Returns the Async::Task so callers can optionally .wait on it.
Implementation
def call(&block)
@call_count += 1
parent.async do |task|
task.defer_stop do
yield
end
@complete_count += 1
rescue => error
@failed_count += 1
Console.error(self, "Background task failed", error)
ensure
@call_count -= 1
end
end