Taskolib  1.3.3
TimeoutTrigger.h
Go to the documentation of this file.
1 
23 // SPDX-License-Identifier: LGPL-2.1-or-later
24 
25 #ifndef TASKOLIB_TIMEOUT_TRIGGER_H_
26 #define TASKOLIB_TIMEOUT_TRIGGER_H_
27 
28 #include "taskolib/Timeout.h"
29 #include "taskolib/time_types.h"
30 
31 namespace task {
32 
50 private:
53 
54 public:
61  TimePoint reset() { start_ = Clock::now(); return start_; }
62 
68  const Timeout get_timeout() const { return timeout_; }
69 
75  void set_timeout(Timeout timeout) { timeout_ = timeout; }
76 
83  TimePoint get_start_time() const { return start_; }
84 
92  bool is_elapsed() const
93  {
94  if (not isfinite(timeout_))
95  return false;
96  return Clock::now() - start_ > static_cast<Timeout::Duration>(timeout_);
97  }
98 };
99 
100 } // namespace task
101 
102 #endif
Declaration of the Timeout class.
Evaluates when the clock is elapsed.
Definition: TimeoutTrigger.h:49
TimePoint reset()
Reset the timeout start time to the current time.
Definition: TimeoutTrigger.h:61
const Timeout get_timeout() const
Get the timeout duration.
Definition: TimeoutTrigger.h:68
Timeout timeout_
Timeout.
Definition: TimeoutTrigger.h:51
void set_timeout(Timeout timeout)
Set the timeout duration.
Definition: TimeoutTrigger.h:75
bool is_elapsed() const
Evaluates if a timeout elapsed.
Definition: TimeoutTrigger.h:92
TimePoint get_start_time() const
Get start time.
Definition: TimeoutTrigger.h:83
TimePoint start_
Starting clock time used to measure the elapsed time.
Definition: TimeoutTrigger.h:52
A type for storing a timeout duration.
Definition: Timeout.h:72
std::chrono::milliseconds Duration
Definition: Timeout.h:74
static constexpr Timeout infinity()
A constant to use for "infinite" timeout durations.
Definition: Timeout.h:124
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
std::chrono::time_point< Clock > TimePoint
Definition: time_types.h:34
Declaration of time-related types.