3#include "../detail/callable/bind.hpp"
4#include "../detail/pool/inline_pool_backend.hpp"
5#include "../detail/pool/shutdown.hpp"
6#include "../detail/pool/worker_context_guard.hpp"
7#include "../detail/try_result.hpp"
8#include "../result.hpp"
9#include "../shutdown_policy.hpp"
13#include <system_error>
25 template <
typename F,
typename... Args>
29 return impl_.
try_submit(std::forward<F>(function), std::forward<Args>(args)...);
32 template <
typename F,
typename... Args>
36 auto submitted =
submit(std::forward<F>(function), std::forward<Args>(args)...);
38 throw std::system_error(submitted.error(),
"inline_pool::submit");
39 return std::move(*submitted);
42 template <
typename F,
typename... Args>
46 return impl_.
try_post(std::forward<F>(function), std::forward<Args>(args)...);
49 template <
typename F,
typename... Args>
53 auto posted =
post(std::forward<F>(function), std::forward<Args>(args)...);
55 throw std::system_error(posted.error(),
"inline_pool::post");
58 template <
typename Iterator>
65 template <
typename Iterator>
71 throw std::system_error(submitted.error(),
"inline_pool::submit_batch");
72 return std::move(*submitted);
75 template <
typename Iterator,
typename Function>
79 static_assert(detail::is_forward_iterator_v<Iterator>,
"parallel_for_each requires at least a forward iterator");
auto submit_batch_or_throw(Iterator begin, Iterator end) -> std::vector< std::future< void > >
auto shutdown(shutdown_policy policy=shutdown_policy::drain) -> result< void >
auto submit(F &&function, Args &&... args) -> result< std::future< detail::bind_result_t< F, Args... > > >
auto wait() -> result< void >
auto submit_or_throw(F &&function, Args &&... args) -> std::future< detail::bind_result_t< F, Args... > >
auto parallel_for_each(Iterator begin, Iterator end, Function &&function) -> result< void >
auto size() const noexcept -> std::size_t
auto submit_batch(Iterator begin, Iterator end) -> result< std::vector< std::future< void > > >
auto pending_tasks() const noexcept -> std::size_t
auto post(F &&function, Args &&... args) -> result< void >
void post_or_throw(F &&function, Args &&... args)
A pool that executes every task inline on the calling thread.
void shutdown(shutdown_policy_backend=shutdown_policy_backend::drain)
void parallel_for_each(Iterator begin, Iterator end, F &&func)
auto try_submit_batch(Iterator begin, Iterator end) -> expected< std::vector< std::future< void > >, std::error_code >
auto try_submit(F &&f, Args &&... args) -> expected< std::future< bind_result_t< F, Args... > >, std::error_code >
auto try_post(F &&f, Args &&... args) -> expected< void, std::error_code >
std::invoke_result_t< decltype(bind_args(std::declval< F >(), std::declval< Args >()...))& > bind_result_t
Result of invoking the decayed callable and arguments stored by bind_args.
constexpr auto to_native(shutdown_policy policy) noexcept -> shutdown_policy_backend
auto try_result(Function &&function) -> decltype(std::forward< Function >(function)())
shutdown_policy
Defines how pools handle pending work during shutdown.
@ drain
Finish queued work before returning from shutdown.