jobber: active_wait_one

This commit is contained in:
2018-12-22 02:25:38 +07:00
parent e865f3d679
commit ff6f80a5ef
2 changed files with 35 additions and 0 deletions

View File

@@ -72,6 +72,7 @@ namespace jobber_hpp
jobber_wait_status wait_all() const noexcept;
jobber_wait_status active_wait_all() noexcept;
jobber_wait_status active_wait_one() noexcept;
template < typename Rep, typename Period >
jobber_wait_status wait_all_for(
@@ -225,6 +226,17 @@ namespace jobber_hpp
: jobber_wait_status::no_timeout;
}
inline jobber_wait_status jobber::active_wait_one() noexcept {
std::unique_lock<std::mutex> lock(tasks_mutex_);
if ( cancelled_ ) {
return jobber_wait_status::cancelled;
}
if ( !tasks_.empty() ) {
process_task_(std::move(lock));
}
return jobber_wait_status::no_timeout;
}
template < typename Rep, typename Period >
jobber_wait_status jobber::wait_all_for(
const std::chrono::duration<Rep, Period>& timeout_duration) const