Stroika Library
3.0d18
Help-Home
Loading...
Searching...
No Matches
WhenTimeExceeded.h
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#ifndef _Stroika_Foundation_Execution_WhenTimeExceeded_h_
5
#define _Stroika_Foundation_Execution_WhenTimeExceeded_h_ 1
6
7
#include "Stroika/Foundation/StroikaPreComp.h"
8
9
#include "
Stroika/Foundation/Time/Realtime.h
"
10
11
/**
12
* \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
13
*/
14
15
namespace
Stroika::Foundation::Execution
{
16
17
/**
18
* \note callIfTakesLongerThan is compared <=, so you can pass in zero to always trigger.
19
*
20
* \par Example Usage
21
* \code
22
* WhenTimeExceeded whenTimeExceeded{1.0s, [] (DurationSeconds timeTaken) { Logger::sThe.Log (Logger::eWarning, "Took along time to do 'x'"); }};
23
* \endcode
24
*
25
* \note this can be hopefully, mostly, optimized away if passed a nullptr_t constructor argument, or perhaps even if passed a null
26
* value of f
27
*/
28
struct
WhenTimeExceeded
{
29
/**
30
* note - the called function f can be nullptr, in which case this does nothing.
31
*/
32
WhenTimeExceeded
(
Time::DurationSeconds
callIfTakesLongerThan, nullptr_t f);
33
WhenTimeExceeded
(
Time::DurationSeconds
callIfTakesLongerThan,
const
function<
void
(
Time::DurationSeconds
)>& f);
34
~WhenTimeExceeded
();
35
36
private
:
37
Time::TimePointSeconds
fStartedAt_;
38
Time::DurationSeconds
fCallIfTakesLongerThan_;
39
function<void (
Time::DurationSeconds
)> fRunIfTakesTooLong_;
40
};
41
42
}
43
44
/*
45
********************************************************************************
46
***************************** Implementation Details ***************************
47
********************************************************************************
48
*/
49
#include "WhenTimeExceeded.inl"
50
51
#endif
/*_Stroika_Foundation_Execution_WhenTimeExceeded_h_*/
Realtime.h
Stroika::Foundation::Time::TimePointSeconds
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Definition
Realtime.h:82
Stroika::Foundation::Time::DurationSeconds
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition
Realtime.h:57
Stroika::Foundation::Execution
Definition
SDKString.inl:7
Stroika::Foundation::Execution::WhenTimeExceeded
Definition
WhenTimeExceeded.h:28
Library
Sources
Stroika
Foundation
Execution
WhenTimeExceeded.h
Generated by
1.9.8