- template <typename Clock, typename Duration = typename Clock::duration>
- bool timed_wait(const std::chrono::time_point<Clock,Duration>& deadline) {
- static_assert(Blocking, "Non-blocking Baton does not support timed wait.");
+ template <typename Rep, typename Period>
+ bool try_wait_for(const std::chrono::duration<Rep, Period>& timeout) {
+ static_assert(
+ Blocking, "Non-blocking Baton does not support try_wait_for.");
+
+ auto deadline = std::chrono::steady_clock::now() + timeout;
+ return try_wait_until(deadline);
+ }
+
+ /// Similar to wait, but with a deadline. The thread is unblocked if the
+ /// deadline expires.
+ /// Note: Only a single call to wait/try_wait_for/try_wait_until is allowed
+ /// during a baton's life-cycle (from ctor/reset to dtor/reset). In other
+ /// words, after try_wait_until the caller can't invoke
+ /// wait/try_wait/try_wait_for/try_wait_until
+ /// again on the same baton without resetting it.
+ ///
+ /// @param deadline Time until which the thread can block
+ /// @return true if the baton was posted to before deadline,
+ /// false otherwise
+ template <typename Clock, typename Duration>
+ bool try_wait_until(
+ const std::chrono::time_point<Clock, Duration>& deadline) {
+ static_assert(
+ Blocking, "Non-blocking Baton does not support try_wait_until.");