ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
deadline.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../time.hpp"
4
5#include <chrono>
6
8{
9
10[[nodiscard]] inline auto
11shutdown_deadline_after(std::chrono::milliseconds timeout) -> std::chrono::steady_clock::time_point
12{
13 using clock = std::chrono::steady_clock;
14 using time_point = clock::time_point;
15
16 auto const now = clock::now();
17 if (timeout <= std::chrono::milliseconds::zero())
18 return now;
19
20 auto const delay = checked_duration_cast<clock::duration>(timeout);
21 if (!delay)
22 return time_point::max();
23
24 auto const deadline = checked_deadline_after(now, delay.value());
25 return deadline ? deadline.value() : time_point::max();
26}
27
28} // namespace threadschedule::detail
Aggregates multiple thread_registry_backend instances into a single queryable view.
auto checked_deadline_after(std::chrono::time_point< Clock, Duration > now, Duration delay) -> expected< std::chrono::time_point< Clock, Duration >, std::error_code >
Definition time.hpp:50
auto shutdown_deadline_after(std::chrono::milliseconds timeout) -> std::chrono::steady_clock::time_point
Definition deadline.hpp:11