You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
589 B
26 lines
589 B
2 years ago
|
#pragma once
|
||
|
|
||
|
#include <functional>
|
||
|
#include <future>
|
||
|
#include <memory>
|
||
|
|
||
|
namespace database {
|
||
|
|
||
|
auto StartDbTask() -> bool;
|
||
|
auto QuitDbTask() -> void;
|
||
|
|
||
|
auto SendToDbTask(std::function<void(void)> fn) -> void;
|
||
|
|
||
|
template <typename T>
|
||
|
auto RunOnDbTask(std::function<T(void)> fn) -> std::future<T> {
|
||
|
std::shared_ptr<std::promise<T>> promise =
|
||
|
std::make_shared<std::promise<T>>();
|
||
|
SendToDbTask([=]() { promise->set_value(std::invoke(fn)); });
|
||
|
return promise->get_future();
|
||
|
}
|
||
|
|
||
|
template <>
|
||
|
auto RunOnDbTask(std::function<void(void)> fn) -> std::future<void>;
|
||
|
|
||
|
} // namespace database
|