EventMiddleware typedef

EventMiddleware = void Function(dynamic event, void next(dynamic))

A typed event bus for inter-module communication.

Features:

  • Source Verification: Ensures events and signals come from the claimed module.
  • Rate Limiting: Protects against message loops or flood attacks.
  • Auto-Cleanup: Automatically expires old or orphaned subscriptions.
  • Middleware Support: Intercepts and modifies events or signals in-flight.

event - The event being processed next - Callback to continue the middleware chain

Example:

EventBus().addMiddleware((event, next) {
  print('Before: ${event.runtimeType}');
  next(event); // Continue chain
  print('After: ${event.runtimeType}');
});

Implementation

typedef EventMiddleware =
    void Function(dynamic event, void Function(dynamic) next);