mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
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:
+8
-14
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user