DEPRECATED - migrated into 3rdparty/stout
.
Provides a simple mechanism to receive notifications as callbacks. This is in contrast to something like absl::Notification
that blocks the calling thread which isn't productve in asynchronous environments where the current thread shouldn't be blocked (or creating a new thread is unnecessarily expensive).
Callbacks are executed in reverse order that they were added! This is an explicit design goal that can be relied on rather than treated as an implementation detail. It's intended to mimic the semantics of how destructors are called for allocations on the stack, i.e., in reverse order of what got constructed.
Watch the notification by calling Watch()
and passing a callback:
stout::Notification<std::string> notification;
notification.Watch([](const std::string& s) {
// Invoked when 'Notification::Notify()' gets invoked.
});
notification.Notify("hello world");
Block the current thread (bewarned) for the notification:
stout::Notification<std::string> notification;
// Thread 1:
auto s = notification.Wait();
// Thread 2:
notification.Notify("hello world");