Make TaskManager independent of Future

`TaskManager` and `Future` where coupled together. When a task is pushed
a future is returned. Also the `Future::Wrap` function was inconvenient
to use.
Now `TaskManager::PushTask` doesn't return a `Future` anymore. This
alows to use different `Future`-like types.
Also it's possible to easily use the `Future` with a different type that
implements a `PushTask` function.
This commit is contained in:
phosit
2025-08-24 09:08:31 +02:00
committed by Phosit
parent 8abe9f6cea
commit d85eef067b
9 changed files with 185 additions and 177 deletions
+8 -14
View File
@@ -41,6 +41,7 @@
#include <cstdio>
#include <fmt/format.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
@@ -107,18 +108,11 @@ static void* MgCallback(mg_event event, struct mg_connection *conn, const struct
std::string uri = request_info->uri;
if (uri == "/download")
{
Threading::TaskManager::GetSingleton().PushTask([&]
{
profiler->SaveToFile();
}).Get();
}
Future{g_TaskManager, std::bind_front(&CProfiler2::SaveToFile, profiler)}.Get();
else if (uri == "/overview")
{
Threading::TaskManager::GetSingleton().PushTask([&]
{
profiler->ConstructJSONOverview(stream);
}).Get();
Future{g_TaskManager,
std::bind_front(&CProfiler2::ConstructJSONOverview, profiler, std::ref(stream))}.Get();
}
else if (uri == "/query")
{
@@ -138,10 +132,10 @@ static void* MgCallback(mg_event event, struct mg_connection *conn, const struct
}
std::string thread(buf);
const char* err = Threading::TaskManager::GetSingleton().PushTask([&]
{
return profiler->ConstructJSONResponse(stream, thread);
}).Get();
const char* err = Future{g_TaskManager,
std::bind_front(&CProfiler2::ConstructJSONResponse, profiler, std::ref(stream),
std::ref(thread))}.Get();
if (err)
{
mg_printf(conn, "%s (%s)", header400, err);