Lightweight
0.20260921.0
Loading...
Searching...
No Matches
CancellationToken.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: Apache-2.0
2
#pragma once
3
4
#include <stdexcept>
5
6
namespace
Lightweight::Async
7
{
8
9
/// @ingroup Async
10
/// Thrown when an asynchronous operation is abandoned because cancellation was requested
11
/// before (or instead of) it producing a result.
12
class
OperationCancelledError
:
public
std::runtime_error
13
{
14
public
:
15
OperationCancelledError
():
16
std::runtime_error {
"Asynchronous operation was cancelled."
}
17
{
18
}
19
};
20
21
/// @file
22
/// Cooperative cancellation for the async layer is expressed with the standard @c std::stop_token.
23
///
24
/// Async methods accept an optional @c std::stop_token (defaulted to @c {}). A default-constructed
25
/// token has no associated stop-state — it is @b non-cancellable (@c stop_requested() and
26
/// @c stop_possible() are always false) and allocates nothing, the cheap default for callers that
27
/// do not pass one. To cancel, a caller holds a @c std::stop_source, passes @c source.get_token()
28
/// where supported, and calls @c source.request_stop().
29
///
30
/// Cancellation is honored cooperatively and only @e before dispatch: the offload runtime checks
31
/// @c stop_requested() before posting a step to the worker and, if set, completes it with
32
/// @ref Lightweight::Async::OperationCancelledError without ever occupying a worker. Once a step has
33
/// begun running, the in-flight blocking ODBC call is @b not interrupted (there is no @c SQLCancel
34
/// integration yet), so a request that arrives after dispatch only takes effect on the next
35
/// not-yet-dispatched step.
36
37
}
// namespace Lightweight::Async
Lightweight::Async::OperationCancelledError
Definition
CancellationToken.hpp:13
Lightweight
Async
CancellationToken.hpp
Generated by
1.9.8