A CancellationToken is an object that can be passed into an function or operation that allows the caller to later request that the operation be cancelled.
Declared in <folly/CancellationToken.h>
class CancellationToken;
A CancellationToken object can be obtained by calling the .getToken() method on a CancellationSource or by copying another CancellationToken object. All CancellationToken objects obtained from the same original CancellationSource object all reference the same underlying cancellation state and will all be cancelled together.
If your function needs to be cancellable but does not need to request cancellation then you should take a CancellationToken as a parameter. If your function needs to be able to request cancellation then you should instead take a CancellationSource as a parameter.
refcode folly/docs/examples/folly/CancellationToken.cpp
| Name | Description |
|---|---|
CancellationToken [constructor] | Constructors |
operator= | Assignment operators |
canBeCancelled | Query whether this CancellationToken can ever have cancellation requested on it. |
isCancellationRequested | Query whether someone has called .requestCancellation() on an instance of CancellationSource object associated with this CancellationToken. |
swap | Swaps the underlying state of the cancellation token with the token that is passed-in. |
| Name | Description |
|---|---|
folly::cancellation_token_merge_fn | Obtain a CancellationToken linked to any number of other CancellationTokens. |
folly::CancellationSource | A CancellationSource object provides the ability to request cancellation of operations that an associated CancellationToken was passed to. |
folly::CancellationCallback | A CancellationCallback object registers the callback with the specified CancellationToken such that the callback will be executed if the corresponding CancellationSource object has the requestCancellation() method called on it. |
folly::operator== | Return whether two tokens share the same underlying cancellation state. |
| Name | Description |
|---|---|
cancellation_token_merge | Merge the given tokens into a single CancellationToken. |
getTerminateCancellationToken | Returns a CancellationToken that can be used to schedule callbacks. The CancellationToken is cancelled when any of SIGTERM and SIGINT signal is received. |
operator!= | Return whether two tokens do not share the same underlying cancellation state. |
coro::co_withCancellation | Attaches a cancellation token to the task. |
coro::co_withCancellation | Attaches a cancellation token to the bound task. |
coro::co_withCancellation | Attaches a cancellation token to the future so awaiting it observes cancellation. |
coro::co_withCancellation | Associates a cancellation token with the wrapped task. |
coro::co_withCancellation | Attaches a cancellation token to the pending next-value operation. |