Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Timeout.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_Timeout_h_
5#define _Stroika_Foundation_Execution_Timeout_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <condition_variable> // for cv_status
10
11#include "Stroika/Foundation/Execution/Exceptions.h"
13
15
16 /**
17 * \brief How Stroika reports a timeout.
18 *
19 * Stroika has no dedicated timeout exception TYPE. A timeout is reported the way every other error is -
20 * as a SystemErrorException (which IS a std::system_error) carrying errc::timed_out - so it is caught
21 * and tested the standard C++ way:
22 *
23 * \code
24 * catch (const system_error& e) {
25 * if (Execution::IsA (e, errc::timed_out)) {
26 * ...
27 * }
28 * }
29 * \endcode
30 *
31 * To raise one, say @see ThrowError (errc::timed_out).
32 *
33 * \note Test the CONDITION (errc::timed_out), NEVER a particular code such as
34 * error_code{ETIMEDOUT, system_category ()}. Only the condition matches timeouts from every
35 * source - libcurl, getaddrinfo, HRESULT, the OS, and Stroika's own waiting primitives.
36 * @see ThrowError for why, and for what errc::timed_out means to Stroika.
37 */
38
39 /**
40 * \brief Throw a timeout (@see ThrowError (errc::timed_out)) if @Time::GetTickCount () is >= the given value.
41 *
42 * This function facilitates writing code like:
43 * Time::TimePointSeconds timeoutAfter = Time::GetTickCount () + 1.0;
44 * do_someting_dont_know_how_long_it_will_take();
45 * Execution::ThrowTimeoutExceptionAfter (timeoutAfter);
46 *
47 * \note ***Cancelation Point***
48 */
49 template <typename EXCEPTION>
50 void ThrowTimeoutExceptionAfter (Time::TimePointSeconds afterTickCount, EXCEPTION&& exception2Throw);
51 void ThrowTimeoutExceptionAfter (Time::TimePointSeconds afterTickCount);
52
53 /**
54 * \brief Throw a timeout (@see ThrowError (errc::timed_out)) if the given condition_variable wait timed out.
55 *
56 * \note - this function may not be called outside the context of a running main.
57 */
58 template <typename EXCEPTION>
59 void ThrowIfTimeout (cv_status conditionVariableStatus, EXCEPTION&& exception2Throw);
60 void ThrowIfTimeout (cv_status conditionVariableStatus);
61
62}
63
64/*
65 ********************************************************************************
66 ***************************** Implementation Details ***************************
67 ********************************************************************************
68 */
69#include "Timeout.inl"
70
71#endif /*_Stroika_Foundation_Execution_Timeout_h_*/
void ThrowTimeoutExceptionAfter(Time::TimePointSeconds afterTickCount, EXCEPTION &&exception2Throw)
How Stroika reports a timeout.
Definition Timeout.inl:21
void ThrowIfTimeout(cv_status conditionVariableStatus, EXCEPTION &&exception2Throw)
Throw a timeout (.
Definition Timeout.inl:44