Jump to a problem, path or page
Jump to a problem, path or page
01 · Frame the problem
Design a single-process publish/subscribe library. Listeners can unsubscribe or add subscriptions while an event is being handled. Slow or throwing listeners need documented behavior.
Publication must define which subscriptions belong to an event and what happens when listeners throw or mutate the registry. Reentrancy is a semantic choice, not just an iteration implementation detail.
02 · Find the design pressure
Begin with tokenized subscriptions and a stable publish snapshot. Iterating the live registry lets callbacks unpredictably skip or add recipients. Preserve snapshot order and isolate failures so one listener or error reporter cannot corrupt dispatch.
03 · Define success
04 · Identify the correctness boundary
Snapshot subscriptions before dispatch so subscribe/unsubscribe during a callback has predictable scope. Preserve registration order within that snapshot and isolate listener failures through a protected error reporter. Reentrant publish takes its own snapshot; it must not corrupt the outer iteration or reuse mutable payload state.
05 · Make it concrete
Listeners A and B are subscribed. A unsubscribes B while handling event 1; B still receives event 1 under snapshot semantics, but not event 2. If A throws, B still runs. If the error reporter also throws, the result records that failure rather than recursively redispatching errors forever.