#pragma once #include #include namespace DB { /// Interface to run task asynchronously with possibility to wait for execution. class Executor { public: virtual ~Executor() = default; virtual std::future execute(std::function task) = 0; }; /// Executes task synchronously in case when disk doesn't support async operations. class SyncExecutor : public Executor { public: SyncExecutor() = default; std::future execute(std::function task) override { auto promise = std::make_shared>(); try { task(); promise->set_value(); } catch (...) { try { promise->set_exception(std::current_exception()); } catch (...) { } } return promise->get_future(); } }; }