Skip to content

Refactor InMemoryEventBus for controlled async dispatch (WebSocket readiness) #41

@patinhooh

Description

@patinhooh

InMemoryEventBus currently uses fire-and-forget async handler execution to keep publishers non-blocking. This works now but will not scale safely once WebSocket broadcasting and higher event volume are introduced.

Current State

  • Publish spawns async handler tasks directly
  • No internal queue or backpressure
  • No safe unsubscribe / lifecycle handling
  • Publishers are non-blocking (must remain so)

Problem

  • Unbounded task creation under load
  • No control over scheduling or throttling
  • Unsafe for long-lived WebSocket handlers
  • No graceful shutdown or drain support

Goal

  • Keep publishers non-blocking
  • Enqueue events internally (e.g. Channel<IEvent>)
  • Centralize dispatch execution
  • Allow future throttling, backpressure, and safe unsubscribe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions