45 return future_.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
58 template<
typename Rep,
typename Period>
59 std::future_status
wait_for(
const std::chrono::duration<Rep, Period>& timeout) {
60 return future_.wait_for(timeout);
118 promise_.set_value(std::move(value));
132 promise_.set_value_at_thread_exit(value);
139 promise_.set_exception_at_thread_exit(exception);
165 promise_.set_value_at_thread_exit();
169 promise_.set_exception_at_thread_exit(exception);
183 promise.
set_value(std::forward<T>(value));
211 template<
typename... Futures>
213 (futures.wait(), ...);
219 template<
typename... Futures>
223 constexpr auto poll_interval = std::chrono::microseconds(100);
226 auto check_future = [&](
auto& future) {
227 if (future.is_ready()) {
236 if ((check_future(futures) || ...)) {
240 std::this_thread::sleep_for(poll_interval);
A future that can be scheduled on a thread pool.
void wait()
Wait until the result is available.
auto then(F &&continuation) -> pool_future< std::invoke_result_t< F, T > >
Chain another operation after this future completes.
bool valid() const
Check if the future is valid.
std::future_status wait_for(const std::chrono::duration< Rep, Period > &timeout)
Wait for the result with timeout.
bool is_ready() const
Check if the future is ready.
T get()
Wait for the result.
pool_future(std::future< T > &&future)
Construct from a std::future.
std::promise< void > promise_
pool_future< void > get_future()
void set_exception_at_thread_exit(std::exception_ptr exception)
void set_value_at_thread_exit()
void set_exception(std::exception_ptr exception)
A promise that can schedule work on a thread pool.
void set_exception_at_thread_exit(std::exception_ptr exception)
Set an exception at thread exit.
pool_future< T > get_future()
Get the associated future.
std::promise< T > promise_
void set_value(T &&value)
Set the value (move)
pool_promise()=default
Default constructor.
void set_exception(std::exception_ptr exception)
Set an exception.
void set_value(const T &value)
Set the value.
void set_value_at_thread_exit(const T &value)
Set the value at thread exit.
Forward declarations for thread system types.
Error codes and utilities for the thread system.
Core threading foundation of the thread system library.
void wait_for_all(Futures &... futures)
Wait for all futures to complete.
pool_future< void > make_ready_future()
Create a future that is already ready with void.
size_t wait_for_any(Futures &... futures)
Wait for any future to complete.
pool_future< T > make_exceptional_future(std::exception_ptr exception)
Create a future that is already ready with an exception.