Player12
An open source football management simulator
Loading...
Searching...
No Matches
background_task.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <future>
12#include <thread>
13#include <type_traits>
14#include <utility>
15
20template <class Function>
21auto launchBackgroundTask(std::jthread& worker, Function function)
22{
23 std::packaged_task<std::invoke_result_t<Function&>()> task(
24 std::move(function));
25 auto result = task.get_future();
26 worker = std::jthread(std::move(task));
27 return result;
28}
auto launchBackgroundTask(std::jthread &worker, Function function)
Definition background_task.h:21