Fork of Tangara with customizations
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.
 
 
 
 
 
 
tangara-fw/src/database/include/db_task.hpp

31 lines
692 B

/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#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