module RatatuiRuby::SyntheticEvents

Ruby-only event queue for synthetic events.

Native events flow through the Rust backend. Synthetic events bypass it. Runtimes (Tea, Kit) check this queue and handle events like Event::Sync specially.

*For runtime authors:* Check pending? each loop iteration after polling native events. When true, pop the event and handle it. For Event::Sync, wait for pending threads and process background results before continuing.

*For app developers:* Push Event::Sync when you need async results before continuing. The runtime will block until all pending work completes. Use this for “ensure saves complete before quit.”

*For test authors:* Use inject_sync between events to create synchronization points. This enables deterministic testing of async behavior.

Example

# Production: ensure async saves finish before exiting
RatatuiRuby::SyntheticEvents.push(RatatuiRuby::Event::Sync.new)

# Runtime authors: check in your event loop
if RatatuiRuby::SyntheticEvents.pending?
  event = RatatuiRuby::SyntheticEvents.pop
  handle_sync if event.sync?
end