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