# eventbus **Repository Path**: proxyxxx/eventbus ## Basic Information - **Project Name**: eventbus - **Description**: No description available - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-08 - **Last Updated**: 2025-05-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
## Overview `eventbus` is a simple, header only C++17 event bus library that doesn't require you to inherit from any sort of `event` class. The library implements the "Mediator" pattern. This pattern is useful when you want components to communicate to each other without necessarily "knowing" about each other. Effectively, this is a thread safe event dispatcher with a list of callbacks. ## Features - **Does not require event object inheritance** A base `Event` class is not requied for use with `dp::event_bus`. Any class/struct can be used as an event object. - **Flexible Callback Types** `eventbus` supports a variety different types of callbacks including: - Lambdas - Class member functions - Free functions - **Flexible Callbacks** No parameter callbacks are also supported as well as taking the event type by value or by `const &`. - **RAII de-registrations** The handler registration objects automatically de-register the handler upon destruction. - **Thread safety** Multiple threads can fire events at once to the same `event_bus`. Handlers can also be registered from different threads. - **Note:** While the library can handle events fired from different threads note that the thread that fires the event is also the thread that the callback will run on. This library does not ensure that the callback is run on the thread it was registered on. This may or may not be the desired behavior especially in the context of something like thread pools. - **Multiple Storage Types** Choose to store event types in the bus either using `std::any` or `std::variant`. ## Usage The basic premise of the `event_bus` is that with it, you can: - Register handlers - Fire events that call the corresponding handlers ### Selecting Storage Type Selecting a storage type is as simple as instantiating the `event_bus`: ```cpp dp::event_bus any_bus; // uses std::any dp::event_bus