Skip to content

🏃 This fast event system allows calls between two interfaces decoupled (sync or async)

License

Notifications You must be signed in to change notification settings

makiolo/fast-event-system

Repository files navigation

Fast Event System

gcc 4.9 / clang 3.6: Build Status

MSVC 2015: Build status

Quality: Codacy Badge codecov

quick-start

$ git clone https://github.com/makiolo/fast-event-system.git
$ cd fast-event-system
$ npm install
$ npm test

Very simple to use

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.

sync

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

async_fast

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

async_delay

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

About

🏃 This fast event system allows calls between two interfaces decoupled (sync or async)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published