Skip to content

Commit 89e3fc9

Browse files
committed
Fix return value for wait_for
1 parent d59d256 commit 89e3fc9

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

include/dispatch_queue.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,28 @@ class dispatch_queue {
113113

114114
/**
115115
* Wait until all pending tasks finish processing.
116-
* @see std::future<T>::wait
117116
*/
118117
void wait();
119118

120119
/**
121120
* Wait until all pending tasks finish processing.
122-
* Blocks until specified `timeout_duration` has elapsed or the result becomes available, whichever comes first.
123-
* The return value indicates why `wait_for` returned.
124-
* @see std::future<T>::wait_for
121+
* Blocks until specified `timeout_duration` has elapsed or all queued tasks complete, whichever comes first.
122+
* @returns `false` if the timeout has expired, otherwise `true`.
125123
*/
126124
template<class Rep, class Period>
127-
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
125+
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
128126
if (worker_pool) {
129127
return worker_pool->wait_for(timeout_duration);
130128
}
131129
else {
132-
return std::future_status::ready;
130+
return true;
133131
}
134132
}
135133

136134
/**
137135
* Wait until all pending tasks finish processing.
138-
* Blocks until the specified `timeout_time` has been reached or the result becomes available, whichever comes first.
139-
* The return value indicates why `wait_until` returned.
140-
* @see std::future<T>::wait_until
136+
* Blocks until the specified `timeout_time` has been reached or all queued tasks complete, whichever comes first.
137+
* @returns `false` if the timeout has expired, otherwise `true`.
141138
*/
142139
template<class Clock, class Duration>
143140
bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {

include/task.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ class task {
102102
* If the task is pending (`get_state() == task_state::pending`), blocks until task finishes or until the specified `timeout_duration` has elapsed.
103103
* Otherwise returns immediately without blocking.
104104
*
105-
* @returns `std::future_status::timeout` if the timeout has expired, otherwise `std::future_status::ready`.
105+
* @returns `false` if the timeout has expired, otherwise `true`.
106106
*/
107107
template<class Rep, class Period>
108-
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const {
108+
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const {
109109
return future->wait_for(timeout_duration);
110110
}
111111

include/task_future.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class task_future_base {
5959
}
6060

6161
template<class Rep, class Period>
62-
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
62+
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
6363
std::unique_lock<std::mutex> lock(mutex);
6464
return condition_variable.wait_for(lock, timeout_duration, wait_predicate());
6565
}

include/worker_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class worker_pool {
4545
void wait();
4646

4747
template<class Rep, class Period>
48-
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
48+
bool wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
4949
std::unique_lock<std::mutex> lock(mutex);
5050
return all_done_condition_variable.wait_for(lock, timeout_duration, wait_predicate());
5151
}

0 commit comments

Comments
 (0)