Skip to content

feat(message-bus)!: rewrite around class-based events and per-broker queues - #878

Open
johngeorgewright wants to merge 15 commits into
masterfrom
dmg-bus
Open

johngeorgewright wants to merge 15 commits into
masterfrom
dmg-bus

Conversation

@johngeorgewright

Copy link
Copy Markdown
Collaborator

Replace the MessageBus API (string event names, tuple args, generators and
RPC-style invokables) with a class-based bus. Events are plain class instances
routed by constructor identity, so EventDescriptions are no longer needed. The
invokable and generator APIs collapse into a single streaming register/invoke
pair, and the RPC-style request/response model is removed. Each broker owns its
own queue, so brokers can be paused and resumed independently.

Also fixes flaws found while reviewing the rewrite, each covered by tests:

  • filters now AND their keys instead of OR
  • each emit() call resolves to its own result rather than a shared promise
  • invoke completion is the settling of each handler, not a finish() count, so a
    filtered-out or negligent handler can no longer hang or truncate the stream
  • invoke gains an error channel: fail-loud by default, isolate with { onError }
  • interceptor routing is cleaned up when a broker aborts
  • queueMethod no longer resets a running queue

BREAKING CHANGE: the entire public API of @plugola/message-bus has changed.

  • MessageBus is replaced by Bus; bus.broker(name) returns a PluginBroker.
  • Events are classes implementing Event (or extending Invocation) and are
    subscribed to by class, not string name. EventDescriptions are removed.
  • Invokables and generators are unified into a streaming API: register a handler
    with broker.register(Invocation, (event, { send, signal }) => ...) and call
    broker.invoke(new Invocation()).collect() / .iterate(). There is no
    finish() — a handler completes when it returns or its promise settles. The
    RPC-style request/response model is removed.
  • Invocation errors are fail-loud by default; pass { onError } to invoke()
    to isolate handlers and keep the stream running.
  • Lifecycle methods are renamed: start/stop are now resume/pause on both
    Bus and PluginBroker.
  • CancelEvent is renamed to CANCEL.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

johngeorgewright and others added 15 commits September 4, 2026 17:24
We only need the one.
…queues

Replace the MessageBus API (string event names, tuple args, generators and
RPC-style invokables) with a class-based bus. Events are plain class instances
routed by constructor identity, so EventDescriptions are no longer needed. The
invokable and generator APIs collapse into a single streaming register/invoke
pair, and the RPC-style request/response model is removed. Each broker owns its
own queue, so brokers can be paused and resumed independently.

Also fixes flaws found while reviewing the rewrite, each covered by tests:
- filters now AND their keys instead of OR
- each emit() call resolves to its own result rather than a shared promise
- invoke completion is the settling of each handler, not a finish() count, so a
  filtered-out or negligent handler can no longer hang or truncate the stream
- invoke gains an error channel: fail-loud by default, isolate with { onError }
- interceptor routing is cleaned up when a broker aborts
- queueMethod no longer resets a running queue

BREAKING CHANGE: the entire public API of @plugola/message-bus has changed.

- `MessageBus` is replaced by `Bus`; `bus.broker(name)` returns a `PluginBroker`.
- Events are classes implementing `Event` (or extending `Invocation<T>`) and are
  subscribed to by class, not string name. `EventDescription`s are removed.
- Invokables and generators are unified into a streaming API: register a handler
  with `broker.register(Invocation, (event, { send, signal }) => ...)` and call
  `broker.invoke(new Invocation()).collect()` / `.iterate()`. There is no
  `finish()` — a handler completes when it returns or its promise settles. The
  RPC-style request/response model is removed.
- Invocation errors are fail-loud by default; pass `{ onError }` to `invoke()`
  to isolate handlers and keep the stream running.
- Lifecycle methods are renamed: `start`/`stop` are now `resume`/`pause` on both
  `Bus` and `PluginBroker`.
- `CancelEvent` is renamed to `CANCEL`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Optionally pass an abort signal in to broker construction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant