Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

3rdparty/stout-notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

status: archive No Maintenance Intended

DEPRECATED - migrated into 3rdparty/stout.

stout::Notification

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.

Usage

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");