feat(message-bus)!: rewrite around class-based events and per-broker queues - #878
Open
johngeorgewright wants to merge 15 commits into
Open
johngeorgewright wants to merge 15 commits into
johngeorgewright wants to merge 15 commits into
Conversation
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.
For a cleaner coding style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
filtered-out or negligent handler can no longer hang or truncate the stream
BREAKING CHANGE: the entire public API of @plugola/message-bus has changed.
subscribed to by class, not string name. EventDescriptions are removed.
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.
to isolate handlers and keep the stream running.
Bus and PluginBroker.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com