#ifndef DATABASE_H_0A27B356 #define DATABASE_H_0A27B356 #include #include #include #include #include #include #include class database { public: // Feel free to throw an exception if the subscriber should be killed. using subscribe_callback_type = std::function; std::string create(std::mt19937& rng); void subscribe(const std::string& token, subscribe_callback_type callback); void post(const std::string& token, const std::string& msg); void setResult(const std::string& token, const std::string& result); const std::string& getResult(const std::string& token); void mark_done(const std::string& token); bool is_done(const std::string& token); private: struct request { std::vector> subscribers; std::string result; bool done = false; }; std::mutex mutex_; std::map requests_; }; #endif /* end of include guard: DATABASE_H_0A27B356 */