EMRY-006: EventBus pub/sub fan-out (bounded, drop-and-count) #54

Merged
vxfemboy merged 2 commits from emry-006-event-bus into main 2026-06-25 01:49:04 +00:00
vxfemboy commented 2026-06-25 01:47:43 +00:00 (Migrated from github.com)

Closes EMRY-006 (#7). Branched off main. Completes M0.

What

crates/emry-core/src/bus.rsEventBus multi-subscriber fan-out over crossbeam_channel. subscribe() returns an independent Receiver; publish(&Event) clones to each live subscriber and never blocks.

Backpressure (review-driven)

Per-subscriber channels are bounded (DEFAULT_SUBSCRIBER_CAPACITY = 16 384) with try_send: a stalled observer (e.g. wedged TUI render) has events dropped and counted (dropped()) instead of growing memory without limit — mirroring the ring buffer policy and the project's 'never harm the run' ethos. Disconnected receivers are pruned.

Verification

  • ./scripts/pre-commit-rust.sh green: fmt, clippy -D warnings, tests, bus.rs 98% lines
  • Tests: 2 subscribers × 100 events in order, no-sub no-op, full-queue drop+count, dead-subscriber pruning, cross-thread delivery

Review notes

  • Took the reviewer's unbounded-growth finding (conf 95) → switched to bounded + drop-count.
  • Kept the lock across fan-out (sends are wait-free try_send; engine drains on one thread) and documented the trade-off rather than adding a per-publish sender-list clone.
Closes EMRY-006 (#7). Branched off `main`. **Completes M0.** ## What `crates/emry-core/src/bus.rs` — `EventBus` multi-subscriber fan-out over `crossbeam_channel`. `subscribe()` returns an independent `Receiver`; `publish(&Event)` clones to each live subscriber and never blocks. ## Backpressure (review-driven) Per-subscriber channels are **bounded** (`DEFAULT_SUBSCRIBER_CAPACITY` = 16 384) with `try_send`: a stalled observer (e.g. wedged TUI render) has events **dropped and counted** (`dropped()`) instead of growing memory without limit — mirroring the ring buffer policy and the project's 'never harm the run' ethos. Disconnected receivers are pruned. ## Verification - `./scripts/pre-commit-rust.sh` green: fmt, clippy `-D warnings`, tests, bus.rs 98% lines - Tests: 2 subscribers × 100 events in order, no-sub no-op, full-queue drop+count, dead-subscriber pruning, cross-thread delivery ## Review notes - Took the reviewer's **unbounded-growth** finding (conf 95) → switched to bounded + drop-count. - Kept the lock across fan-out (sends are wait-free `try_send`; engine drains on one thread) and documented the trade-off rather than adding a per-publish sender-list clone.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
femboy/emry!54
No description provided.