Skip to main content

Module reactor

Module reactor 

Source
Expand description

reactor: the bridge that makes a SubEtha ring a first-class async source ACROSS processes, not just across threads.

Intra-process async is direct: the producer holds the consumer’s Waker and fires it on push (see crate::waker_ring). Across processes the producer is in another address space and cannot touch a local Waker, so a parked future needs something in THIS process to notice the cross-process publish and fire its Waker. That is the reactor: one background thread per process that blocks on the MMF CrossProcessWaker, and when another process publishes, fires the local Waker of the future parked on the ring. It is the epoll/IOCP reactor pattern with the readiness source being a shared-memory ring head instead of a socket.

§One surface, two locales

ReactiveReceiver::recv returns the same future whether the producer is a thread or a process:

  • anon_pair builds an intra-process channel; the sender fires the receiver’s Waker directly, no reactor thread.
  • receiver_cross / sender_cross build the cross-process halves over a shared MMF ring + named waker; a reactor thread in the consumer bridges the publish to the local Waker.

Unlike crate::async_ring, which spawns one OS thread per in-flight future, the reactor uses ONE thread per process regardless of how many futures park on the ring.

§block_on

block_on is a minimal thread-parking driver: it sleeps the calling thread between polls and is unparked by the future’s Waker. Paired with the reactor, a consumer process genuinely sleeps (both the driver thread and the reactor thread park in the kernel) until another process publishes - no busy-spin.

Structs§

ReactiveReceiver
Consumer half. recv() is an .await-able future that resolves when an item arrives, suspending the task until then - off-thread across threads OR across processes, behind the same call.
ReactiveRecv
Future returned by ReactiveReceiver::recv.
ReactiveSender
Producer half. try_send publishes the payload and signals the consumer - a direct Waker fire intra-process, an MMF wake cross-process.

Functions§

anon_pair
Intra-process reactive channel: the sender fires the receiver’s Waker directly on push. No reactor thread. capacity must be a power of two.
block_on
Drive a future to completion on the current thread, parking the thread between polls. The future’s Waker unparks it; a reactor (or a local sender) fires that Waker on readiness.
receiver_cross
Cross-process consumer half. Spawns a reactor thread that blocks on the shared waker and fires the local Waker of the future parked on the ring whenever the producer process publishes.
sender_cross
Cross-process producer half over a shared MMF ring + named waker. The two processes share the same ring file and the same waker file.