Skip to content

Commit 7b5e3f9

Browse files
committed
feat: provide bus access in handlers and rework internal dispatch
- Updates EventHandler and SyncEventHandler traits to take &EventBus as a parameter, allowing handlers to publish events or query stats. - Simplifies internal architecture by removing theFailure/DeadLetter control loop and per-listener worker tasks. - Overhauls async dispatch to spawn tracked Tokio tasks directly with global concurrency limits. - Splits subscription policies into mode-specific AsyncSubscriptionPolicy and SyncSubscriptionPolicy types. - Improves graceful shutdown logic to drain accepted publishes and wait for all tracked async work.
1 parent 4527f41 commit 7b5e3f9

165 files changed

Lines changed: 3544 additions & 4523 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
.env
66
/bup
7-
/docs/
7+
/docs

CHANGELOG.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,56 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.0] - 2026-04-16
9+
10+
### Breaking Changes
11+
12+
- Subscription policy configuration is now mode-specific:
13+
- `AsyncSubscriptionPolicy { max_retries, retry_strategy, dead_letter }`
14+
- `SyncSubscriptionPolicy { priority, dead_letter }`
15+
- `SubscriptionDefaults { policy, sync_policy }`
16+
- `#[handler]` and `#[event_listener]` now reject `priority` on async handlers with explicit compile-time diagnostics.
17+
- `EventBusBuilder::default_subscription_policies(...)` and `TestBusBuilder::default_subscription_policies(...)` now replace the old singular
18+
default-policy configuration and select async vs sync defaults by handler mode.
19+
- `EventHandler::handle` now takes `&EventBus` as a second parameter:
20+
`fn handle(&self, event: &E, bus: &EventBus) -> impl Future<Output = HandlerResult> + Send`.
21+
- `SyncEventHandler::handle` now takes `&EventBus` as a second parameter:
22+
`fn handle(&self, event: &E, bus: &EventBus) -> HandlerResult`.
23+
- Sync closure handlers now require the signature `Fn(&E, &EventBus) -> HandlerResult`.
24+
- Async closure handlers now require the signature `Fn(E, EventBus) -> Fut`.
25+
- Removed **Once-off subscriptions.** `EventBus::subscribe_once()`
26+
27+
### Changed
28+
29+
- Removed the failure/dead-letter control loop; terminal listener failures are now finalized directly.
30+
- Async dispatch now spawns one tracked Tokio task per listener invocation instead of routing through per-listener runtimes.
31+
- Shutdown now stops ingress, drains accepted publish dispatch tasks, and waits for tracked async work before timing out or aborting tasks.
32+
- Equal-priority listener ordering is now deterministic FIFO by registration order during snapshot rebuilds.
33+
- `EventBus::subscribe()` now picks defaults by dispatch mode instead of normalizing a catch-all public policy.
34+
- `BusStats::in_flight_async` now reports tracked in-flight async tasks.
35+
- `EventBus::is_healthy()` now reflects whether the bus is still running rather than the status of a separate control task.
36+
- `README.md`, `USAGE.md`, examples, and inline docs were updated to reflect the split async/sync policy model and direct async task spawning.
37+
38+
### Fixed
39+
40+
- `SubscriptionGuard::drop` no longer panics when dropped outside an active Tokio runtime; it only spawns best-effort async cleanup when a runtime
41+
handle is available.
42+
- Fixed a shutdown hang where queued async work could miss job-completion accounting if listener runtime state dropped before the worker finished.
43+
44+
### Added
45+
46+
- Trybuild compile-fail coverage for `jaeb-macros` and `summer-jaeb` macros, including async-priority rejection and invalid handler/dead-letter
47+
signatures.
48+
- Handlers can now publish events, query `stats`, or perform
49+
other bus operations directly from inside the handler body via the `bus` parameter.
50+
- `#[handler]` macro: declare `bus: &EventBus` as an optional parameter in handler
51+
functions to receive bus access. Dead-letter handlers (`#[dead_letter_handler]`)
52+
cannot use this parameter (compile-time error).
53+
- `#[event_listener]` macro: same support — declare `bus: &EventBus` alongside
54+
`Component<T>` params. Dead-letter listeners cannot use this parameter.
55+
- `tests/bus_in_handler.rs` — integration tests covering async/sync struct handlers,
56+
async/sync closure handlers, and the `#[handler]` macro all using bus access.
57+
858
## [0.4.0] - 2026-04-12
959

1060
### Added
@@ -23,11 +73,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2373
are a compile-time error.
2474
- `#[handler]` and `#[dead_letter_handler]` support `Dep<T>` parameters for
2575
build-time dependency injection.
26-
- Supported syntax forms: `Dep(name): Dep<T>` (destructured) and
27-
`name: Dep<T>` (plain identifier).
28-
- Multiple `Dep<T>` parameters are supported.
29-
- Missing dependencies return `EventBusError::MissingDependency` at build
30-
time.
76+
- Supported syntax forms: `Dep(name): Dep<T>` (destructured) and
77+
`name: Dep<T>` (plain identifier).
78+
- Multiple `Dep<T>` parameters are supported.
79+
- Missing dependencies return `EventBusError::MissingDependency` at build
80+
time.
3181
- `EventBusError::MissingDependency(String)` variant.
3282
- `tests/builder_handlers.rs` — integration tests for descriptor and DI
3383
registration.
@@ -548,7 +598,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
548598
- Graceful `shutdown()` that drains queued messages and waits for in-flight
549599
async handlers.
550600
- `EventBus::builder()` with `EventBusBuilder` for fine-grained configuration:
551-
- `buffer_size` -- internal channel capacity.
552601
- `handler_timeout` -- per-invocation timeout; exceeded handlers are treated
553602
as failures eligible for retry / dead-letter.
554603
- `max_concurrent_async` -- semaphore-bounded async task concurrency.

0 commit comments

Comments
 (0)