43 using Ptr = std::unique_ptr<ThreadPool>;
58 void postTask(
const std::function<
void()> &task);
64 void postTask(
const std::vector<std::function<
void()>> &tasks);
73 template<
typename FUNCTION,
typename... ARGS>
75 auto bound_function = [func = std::forward<FUNCTION>(
f), args = std::make_tuple(std::forward<ARGS>(args)...)]()
mutable {
76 std::apply(std::move(func), std::move(args));
78 this->
postTask(std::move(bound_function));
87 template<
class RETURN_TYPE>
88 std::shared_future<RETURN_TYPE>
postTask(
const std::function<RETURN_TYPE()> &tasks);
95 [[nodiscard]]
size_t size() noexcept;
96 [[nodiscard]]
bool empty() noexcept;
97 [[nodiscard]] const std::
string &
getName()
const {
return name; }
109 std::queue<std::function<void()>>
tasks;
112 std::shared_ptr<RuntimeData>
data;
127 using TaskPtr = std::shared_ptr<std::packaged_task<RETURN_TYPE()>>;
128 TaskPtr packaged_task = std::make_shared<std::packaged_task<RETURN_TYPE()>>(task);
129 std::shared_future<RETURN_TYPE> future(packaged_task->get_future());
131 this->
postTask([task = std::move(packaged_task)]()
mutable {