$ show spinettaro/delphi-event-bus
The Delphi Event Bus (DEB) is a publish/subscribe framework designed to decouple application components in Delphi applications. It provides an attribute-based API for declaring subscribers, supports thread-specific event delivery (main, background, async), and enables contextual routing of events. The library is built on Delphi's RTTI system to automatically discover and register subscriber methods marked with custom attributes. The architecture centers around a central event bus (accessible via a global singleton or multiple instances) that manages subscriptions and dispatches events. Core components include subscription management (EventBus.Core.pas), RTTI helpers for attribute discovery (EventBus.Helpers.pas), and subscription data structures (EventBus.Subscribers.pas). The library demonstrates strong engineering practices through its thread-safe implementation, comprehensive test suite using DUnitX, and multiple sample applications showcasing usage in VCL and FireMonkey contexts. Key features include interface-typed events for type-safe data transfer, channel-based string messaging, and a dedicated thread pool for background operations (introduced in version 2.1). The library targets Delphi 2010 and later, including Alexandria, and is designed with a 'keep it simple' philosophy, minimizing configuration through convention over configuration.
The LLM identified 3 files worth highlighting for reuse:
Implements the core event bus logic including subscription management, thread-safe event posting, and dispatching to subscribers based on thread mode (Main, Background, Async, Posting). Demonstrates non-obvious skill in handling concurrency and RTTI-based subscription resolution.
Provides RTTI utility functions to discover methods marked with custom attributes (such as [Subscribe] and [Channel]) and to inspect method parameters. This isolated utility encapsulates the complexity of Delphi's RTTI system, making it reusable in any project requiring attribute-based metadata extraction.
Defines the data structures for storing subscriber information (including event type, method reference, thread mode, channel, and context) and contains validation logic for subscriptions. While coupled to the core, it represents a well-encapsulated concern that could be reused in similar publish/subscribe implementations.