$ git clone https://github.com/makiolo/fast-event-system.git
$ cd fast-event-system
$ npm install
$ npm test
Fast event system is a library for resolve observer pattern in a functional way. Is a library very easy to use, only have 3 objects: sync, async_fast and async_delay.
I will explain sync object with minimal examples:
// instanciate
fes::sync<bool> key_A;
Now, you can connect functors, lambdas ...:
key_A.connect([](bool press)
{
if(press)
std::cout << "pressed key A" << std::endl;
else
std::cout << "released key A" << std::endl;
});
And finally, something notify using operator() and all functors connected will receive this.
key_A(true); // notify to subscribers
All objetcs in fes, use variadic templates, new interfaces can be created in compile time:
fes::sync<std::string, int, std::string> civilian;
civilian.connect([](const std::string& name, int age, const std::string& country)
{
std::cout << "new civilian registered" << std::endl;
});
Works equal than sync but data is saved in buffer.
key_A(true); // saved in queue
key_A(true); // saved in queue
key_A(true); // saved in queue
Now, we have three messages waiting in queue. For dispatching, type:
key_A.update(); // notify to subscribers
Works equal than async_fast but data can send delayed. The time delayed is specified in second parameter of operator(): First parameter is priority (more high, is more urgent):
key_A(0, 2000, true); // saved in queue (with your delayed time)
We can use .get() / .update() / .fortime() for dispatching:
// receive message with blocking:
auto one = key_A.get();
For dispatching a fixed time(dispathing multiples messages), you can use .fortime():
// dispatching for 5 seconds
key_A.fortime(5000);