{"id":13619906,"url":"https://github.com/DeveloperPaul123/eventbus","last_synced_at":"2025-04-14T18:32:41.096Z","repository":{"id":39158167,"uuid":"209380776","full_name":"DeveloperPaul123/eventbus","owner":"DeveloperPaul123","description":"A simple, header only event bus library written in modern C++17.","archived":false,"fork":false,"pushed_at":"2025-04-03T15:04:55.000Z","size":756,"stargazers_count":155,"open_issues_count":4,"forks_count":16,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2025-04-05T02:05:59.303Z","etag":null,"topics":["c-plus-plus","c-plus-plus-17","c-plus-plus-library","callbacks","cmake","cplusplus","cpp","cpp-library","cpp17","cpp17-library","cross-platform","event-bus","eventbus","events","flexible-callbacks","hacktoberfest","header-only","library","modern-cpp","no-dependencies"],"latest_commit_sha":null,"homepage":"https://developerpaul123.github.io/eventbus/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeveloperPaul123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"DeveloperPaul123"}},"created_at":"2019-09-18T18:46:04.000Z","updated_at":"2025-03-30T14:30:54.000Z","dependencies_parsed_at":"2024-11-08T06:31:29.181Z","dependency_job_id":"873ce5d9-af21-4813-b76f-ce4daaa9ba97","html_url":"https://github.com/DeveloperPaul123/eventbus","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Feventbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Feventbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Feventbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Feventbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeveloperPaul123","download_url":"https://codeload.github.com/DeveloperPaul123/eventbus/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248936960,"owners_count":21186133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","c-plus-plus-17","c-plus-plus-library","callbacks","cmake","cplusplus","cpp","cpp-library","cpp17","cpp17-library","cross-platform","event-bus","eventbus","events","flexible-callbacks","hacktoberfest","header-only","library","modern-cpp","no-dependencies"],"created_at":"2024-08-01T21:00:50.022Z","updated_at":"2025-04-14T18:32:41.089Z","avatar_url":"https://github.com/DeveloperPaul123.png","language":"C++","readme":"\u003cp align=\"center\"\u003e\n  \n\u003cimg src=\"https://socialify.git.ci/DeveloperPaul123/eventbus/image?font=Bitter\u0026forks=1\u0026language=1\u0026logo=https%3A%2F%2Fraw.githubusercontent.com%2FDeveloperPaul123%2Feventbus%2Fdevelop%2Fart%2Fexport%2Fbus_icon.svg\u0026pattern=Circuit%20Board\u0026stargazers=1\u0026theme=Dark\" alt=\"eventbus\" width=\"640\" height=\"320\" /\u003e\n  \n  \u003cbr\u003e\n  \u003cbr\u003e\n  \n  \u003ca href=\"https://www.apache.org/licenses/LICENSE-2.0.html\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache 2.0-blue\" alt=\"License Apache 2.0\"\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://github.com/DeveloperPaul123/eventbus/stargazers\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Say%20Thanks-👍-1EAEDB.svg\" alt=\"Say thanks\"\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://discord.gg/CX2ybByRnt\"\u003e\n    \u003cimg alt=\"Discord\" src=\"https://img.shields.io/discord/652515194572111872\"\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://github.com/DeveloperPaul123/eventbus/actions\"\u003e\n    \u003cimg alt=\"Windows\" src=\"https://github.com/DeveloperPaul123/eventbus/workflows/Windows/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/DeveloperPaul123/eventbus/actions\"\u003e\n    \u003cimg alt=\"Ubuntu\" src=\"https://github.com/DeveloperPaul123/eventbus/workflows/Ubuntu/badge.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\n`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.\n\n## Features\n\n- **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.\n- **Flexible Callback Types** `eventbus` supports a variety different types of callbacks including:\n  - Lambdas\n  - Class member functions\n  - Free functions\n- **Flexible Callbacks** No parameter callbacks are also supported as well as taking the event type by value or by `const \u0026`.\n- **RAII de-registrations** The handler registration objects automatically de-register the handler upon destruction.\n- **Thread safety** Multiple threads can fire events at once to the same `event_bus`. Handlers can also be registered from different threads.\n  - **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.\n- **Multiple Storage Types** Choose to store event types in the bus either using `std::any` or `std::variant`.\n\n## Usage\n\nThe basic premise of the `event_bus` is that with it, you can:\n\n- Register handlers\n- Fire events that call the corresponding handlers\n\n### Selecting Storage Type\n\nSelecting a storage type is as simple as instantiating the `event_bus`:\n\n```cpp\ndp::event_bus any_bus; // uses std::any\ndp::event_bus\u003cevent_t_1, event_t_2\u003e variant_bus; // uses std::variant\n```\n\nDeclaring the `event_bus` with no template arguments will default to using `std::any` as the storage type. If you want to use `std::variant` you must specify the event types you want to use.\n\n### Define An Event Object\n\nThe \"event\" object can be any class or structure you want.\n\n### Registering Handlers\n\n#### Free function\n\n````cpp\nvoid event_callback(event_type evt)\n{\n    // event callback logic...\n}\n\ndp::event_bus evt_bus;\nconst auto registration_handler = evt_bus.register_handler\u003cevent_type\u003e(\u0026event_callback)\n````\n\n#### Lambda\n\n````cpp\ndp::event_bus evt_bus;\nconst auto registration_handler = evt_bus.register_handler\u003cevent_type\u003e([](const event_type\u0026 evt)\n{\n    // logic code...\n});\n````\n\n#### Class Member Function\n\n````cpp\nclass event_handler\n{\n    public:\n        void on_event(event_type type)\n        {\n            // handler logic...\n        }\n};\n\n// other code\ndp::event_bus evt_bus;\nevent_handler handler;\nconst auto registration_handler = evt_bus.register_handler\u003cevent_type\u003e(\u0026handler, \u0026event_handler::on_event);\n````\n\n**Note:** You can't mix a class instance of type `T` with the member function of another class (i.e. `\u0026U::function_name`).\n\n#### Firing Events\n\n````cpp\nevent_type evt\n{\n    // data and info..\n};\ndp::event_bus evt_bus;\nevt_bus.fire_event(evt); // all connect handler for the given event type will be fired.\n````\n\nA complete example can be seen in the [demo](https://github.com/DeveloperPaul123/eventbus/tree/develop/demo) project.\n\n## Integration\n\n`eventbus` is a header only library. All the files you need are in the `eventbus/include` folder. To use the library just include `eventbus/event_bus.hpp`.\n\n### CMake\n\n`eventbus` defines three CMake `INTERFACE` targets that can be used in your project:\n\n- `eventbus`\n- `eventbus::eventbus`\n- `dp::eventbus`\n\n````cmake\nfind_package(dp::eventbus REQUIRED)\n````\n\nAlternatively, you can use something like [CPM](https://github.com/TheLartians/CPM) which is based on CMake's `Fetch_Content` module.\n\n````cmake\nCPMAddPackage(\n    NAME eventbus\n    GITHUB_REPOSITORY DeveloperPaul123/eventbus\n    GIT_TAG #053902d63de5529ee65d965f8b1fb0851eceed24 change this to latest commit/release tag\n)\n````\n\n### vcpkg\n\n:construction: This library will be on `vcpkg` soon. :construction:\n\n## Limitations\n\nIn general, all callback functions **must** return `void`. Currently, `eventbus` only supports single argument functions as callbacks.\n\nThe following use cases are not supported:\n\n- Registering a callback inside an event callback.\n- De-registering a callback inside an event callback.\n\n## Contributing\n\nIf you find an issue with this library please file an [issue](https://github.com/DeveloperPaul123/eventbus/issues). Pull requests are also welcome! Please see the [contribution guidelines](CONTRIBUTING.md) for more information.\n\n## License\n\nThe project is licensed under the Apache License Version 2.0. See [LICENSE](LICENSE) for more details.\n\n## Author\n\n| [\u003cimg src=\"https://avatars0.githubusercontent.com/u/6591180?s=460\u0026v=4\" width=\"100\"\u003e\u003cbr\u003e\u003csub\u003e@DeveloperPaul123\u003c/sub\u003e](https://github.com/DeveloperPaul123) |\n|:----:|\n\n## Contributors\n\nSee [here](https://github.com/DeveloperPaul123/eventbus/graphs/contributors) for a list of contributors.\n","funding_links":["https://github.com/sponsors/DeveloperPaul123"],"categories":["C++","Event Handling Mechanisms"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeveloperPaul123%2Feventbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDeveloperPaul123%2Feventbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeveloperPaul123%2Feventbus/lists"}