English | 简体中文
Core files:
eventbus.hpp: single-header EventBus implementation.simple_test.cpp: basic behavior and key-semantics tests.test_full.cpp: complete behavior, statistics, conditional publishing, and thread-safety examples.test_complex_types.cpp: complex payload-type tests.example_simple.cpp: application-style usage examples.
Build and run support:
CMakeLists.txt: CMake targets and CTest tests.build.bat: Windows build script.demo.bat: demonstration script.
Documentation:
../README.md: complete usage and API reference.QUICK_START.md: quick-start guide.PROJECT_SUMMARY.md: current technical implementation summary.DELIVERY_NOTES.md: these delivery notes.
eventbus::EventBus bus;
auto id = bus.subscribe("event", [](const std::string& value) {
std::cout << value << "\n";
});
auto result = bus.publish("event", "payload");
(void)bus.unsubscribe("event", id);EventBus does not serialize subscription callbacks. Applications are responsible for synchronizing shared state inside their callbacks.
Stateless callbacks, or callbacks with internal synchronization, can be subscribed directly:
bus.subscribe("fast", [](int value) {
(void)value;
});The same callback may be invoked concurrently by multiple publishing threads.
- Thread-safe subscription, publishing, and unsubscription from multiple threads.
- Concurrent callback execution by default, with no callback-level execution lock.
publish()returns aPublishResult.- Callback exceptions are counted as failures.
- Type mismatches are counted.
const char*tostd::string/std::string_viewconversion.std::stringtostd::string_viewconversion.- Complex STL types and custom payload types.
- Unsubscription waits for callbacks already in progress to finish.
Recommended validation command:
cmake -S . -B build
cmake --build build --config Debug
ctest --test-dir build -C Debug --output-on-failure --timeout 30Additional compilation checks used:
g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c simple_test.cpp -o build/simple_test_gcc.o
g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c test_full.cpp -o build/test_full_gcc.o
g++ -std=c++17 -Wall -Wextra -Wpedantic -I. -c test_complex_types.cpp -o build/test_complex_types_gcc.o- Include only
eventbus.hpp. - Callbacks must return
void. - Callbacks cannot use non-const lvalue-reference parameters.
publish()is synchronous; it is not an asynchronous post operation.- Large payloads are copied or moved into the dispatch tuple. Prefer
std::shared_ptr<const T>or aconst T*with an explicit lifetime. - Bind member-function callbacks with a lambda and ensure the object's lifetime covers the subscription.
unsubscribe(),unsubscribe_all(), andclear()may wait for callbacks in progress. Evaluate their latency impact before calling them on latency-sensitive threads.
- The event-name API still uses
const std::string&. - Hot paths still incur
std::anytype-erasure and argument-packing costs. - The current version does not provide an asynchronous executor, task queue, or backpressure.
- No production benchmark report is included. Measure performance with a dedicated benchmark on the target platform.