Single header only, asynchronous observer structure. Connection is broken when subject or subscriber gets out of scope. Connection itself is thread-safe.
Add the header observer/include/csari/observer.hpp
to your project.
auto subject = csari::Subject<int>{};
auto const subscription = subject.subscribe(
[](int const value) {
// Do something...
});
subject << 42;
More uses are in unit tests test/src/unit.cpp
.
Callback functions are called on the sender's thread; i.e. this library does not provide an event loop. If the sender can be in a different thread, please ensure that callback functions are thread-safe.
RxCpp: Long learning curve and a little too big for my taste. It has A LOT of features. I definitely recommend going with RxCpp for new projects with a need for a strong event architecture.
Boost: Boost has a solution for almost everything. It has lots of features but also carries a lot of the dependencies with it. Use it instead if you already have boost in your system.
Qt: Qt has its own event loop and signals and slots. It has a lot of dependencies which may or may not be necessary for your system.
Daniel Dinu's Observable: Started off with a very similar fashion, Daniel Dinu also has a simple observable library. His library, however, did not have two features I needed at the time I wrote this one: thread-safety and (more than one) memory.