#ifndef _ASYNCMANAGER_HPP #define _ASYNCMANAGER_HPP #include "Runtime.hpp" #include #include #include "basic-coro/AwaitableTask.hpp" #include "basic-coro/SingleEvent.hpp" class Runtime; enum class AsyncResult { Error, Success }; class AsyncManager { public: using SockFuture = basiccoro::SingleEvent; using SockFutureUnique = std::unique_ptr; using SockFutureMap = std::unordered_multimap; private: Runtime& runtime; SockFutureMap sockReads; SockFutureMap sockWrites; bool stopping = false; static void cleanFutureMap(SockFutureMap&); public: AsyncManager(Runtime& runtime) : runtime(runtime) {} AsyncManager(AsyncManager&) = delete; AsyncManager(const AsyncManager&) = delete; AsyncManager(AsyncManager&&) = delete; void run(); void stop() { stopping = true; } basiccoro::AwaitableTask waitRead(int fd) { auto event = std::make_unique(); auto eventPtr = event.get(); sockReads.emplace(fd, std::move(event)); co_return co_await *eventPtr; } basiccoro::AwaitableTask waitWrite(int fd) { auto event = std::make_unique(); auto eventPtr = event.get(); sockWrites.emplace(fd, std::move(event)); co_return co_await *eventPtr; } auto& getRuntime() const { return runtime; } }; #endif