# eventbus2 **Repository Path**: vicopei/eventbus2 ## Basic Information - **Project Name**: eventbus2 - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-26 - **Last Updated**: 2024-05-26 ## 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 libraryimplements 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. ## Usage The basic premise of the `event_bus` is that with it, you can: * Register handlers * Fire events that call the corresponding handlers ### Define An Event Object The "event" object can be any class or structure you want. ### Registering Handlers #### Free function ````cpp void event_callback(event_type evt) { // event callback logic... } dp::event_bus evt_bus; const auto registration_handler = evt_bus.register_handler