https://github.com/andsmedeiros/fuss
Efficient in-process pub/sub pattern for C++
https://github.com/andsmedeiros/fuss
Last synced: 7 months ago
JSON representation
Efficient in-process pub/sub pattern for C++
- Host: GitHub
- URL: https://github.com/andsmedeiros/fuss
- Owner: andsmedeiros
- License: mit
- Archived: true
- Created: 2022-01-06T12:58:04.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-11T15:09:58.000Z (almost 4 years ago)
- Last Synced: 2025-03-30T21:46:22.797Z (8 months ago)
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesomecpp - fuss - - efficient in-process pub/sub pattern for C++. (Concurrency)
README
# FUSS
FUSS is a simple and efficient pub/sub pattern implementation aimed for C++17 programs with an intuitive interface.
It consists of a single header file and has no external dependencies.
## Features
- Simple, efficient, small and elegant. Just read the code!
- Leverages modern C++ to provide an intuitive and pleasant API.
- Avoids unnecessary dynamic memory as much as possible.
- No virtual functions.
- No RTTI.
## Example
```C++
#include
// Define what messages are available to be published.
struct greeting : fuss::message<> {};
// Note that messages can have parameters.
struct echo : fuss::message {};
// Create a publisher object
struct noisy : fuss::shouter {
void greet() {
// Publishes the `greeting` message.
// `shout()` is protected, so we create a member function to call it
shout();
}
void repeat(const std::string &s) {
// Publishes the `echo` message with a string as parameter
shout(s);
}
};
// Instantiate the publisher
noisy n;
// Subscribe to the messages
auto greeting_listener = n.listen([]() {
std::cout << "Hello world!" << std::endl;
});
n.listen([](std::string s) {
std::cout << s << std::endl;
});
n.greet(); // prints 'Hello world!'
n.repeat("What a fuss!"); // prints 'What a fuss!'
// Unsubscribe from a message
n.unlisten(greeting_listener);
n.greet(); // doesn't print anything
```
## Copyright
Copyright André Medeiros 2022
Contact: andre@setadesenvolvimentos.com.br