#ifndef _EVENT_ #define _EVENT_ #include #include #include #include #include "loop.hpp" using namespace std; namespace marcelb { #ifndef ON_ASYNC #define ON_ASYNC AsyncLoop on_async; #endif template class event { private: unordered_map> events; public: void on(const string& key, function callback) { events[key] = callback; } template void emit(const string& key, Args... args) { auto it = events.find(key); if (it != events.end()) { auto callback = bind(it->second, forward(args)...); on_async.put_task(callback); } } }; } #endif