Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
WhenTimeExceeded.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6
7 /*
8 ********************************************************************************
9 ************************ Execution::WhenTimeExceeded ***************************
10 ********************************************************************************
11 */
12 inline WhenTimeExceeded::WhenTimeExceeded ([[maybe_unused]] Time::DurationSeconds callIfTakesLongerThan, [[maybe_unused]] nullptr_t f)
13 : fRunIfTakesTooLong_{nullptr}
14 {
15 }
16 inline WhenTimeExceeded::WhenTimeExceeded (Time::DurationSeconds callIfTakesLongerThan, const function<void (Time::DurationSeconds)>& f)
17 : fCallIfTakesLongerThan_{callIfTakesLongerThan}
18 , fRunIfTakesTooLong_{f}
19 {
20 if (f != nullptr) {
21 fStartedAt_ = Time::GetTickCount ();
22 }
23 }
24 inline WhenTimeExceeded::~WhenTimeExceeded ()
25 {
26 if (fRunIfTakesTooLong_ != nullptr) {
27 Time::DurationSeconds timeTaken = Time::GetTickCount () - fStartedAt_;
28 if (timeTaken >= fCallIfTakesLongerThan_) {
29 IgnoreExceptionsForCall (fRunIfTakesTooLong_ (timeTaken));
30 }
31 }
32 }
33
34}
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
WhenTimeExceeded(Time::DurationSeconds callIfTakesLongerThan, nullptr_t f)