timeout.hpp
1 #ifndef XXHR_TIMEOUT_H
2 #define XXHR_TIMEOUT_H
3 
4 #include <chrono>
5 #include <cstdint>
6 
7 #include <limits>
8 #include <stdexcept>
9 #include <string>
10 #include <type_traits>
11 
12 namespace xxhr {
13  using namespace std::literals::chrono_literals; // Improves readability of user code by allowing to write suffixes.
14 
21 class Timeout {
22  public:
23  Timeout(const std::chrono::milliseconds& duration) : ms{duration} {}
24  Timeout(const std::int32_t& milliseconds) : Timeout{std::chrono::milliseconds(milliseconds)} {}
25  template< class Rep, class Period >
26  Timeout(const std::chrono::duration<Rep, Period> duration)
27  : Timeout(std::chrono::duration_cast<std::chrono::milliseconds>(duration)) {}
28 
29  std::chrono::milliseconds ms;
30 };
31 
32 } // namespace xxhr
33 
34 #endif
xxhr::Timeout
A timeout specification to cut short slow HTTP queries.
Definition: timeout.hpp:21
xxhr
main library namespace
Definition: api.hpp:20