folly::CancellationSource

A CancellationSource object provides the ability to request cancellation of operations that an associated CancellationToken was passed to.

Synopsis

Declared in <folly/CancellationToken.h>

class CancellationSource;

Description

Example usage:

CancellationSource cs; Future<void> f = startSomeOperation(cs.getToken());

// Later... cs.requestCancellation();

refcode folly/docs/examples/folly/CancellationSource.cpp

Member Functions

NameDescription
CancellationSource [constructor]Constructors
operator= Assignment operators
canBeCancelled Query if cancellation can be requested through this CancellationSource object. This will only return false if the CancellationSource object has been moved-from.
getToken Obtain a CancellationToken linked to this CancellationSource.
isCancellationRequested Query if cancellation has already been requested on this CancellationSource or any other CancellationSource object copied from the same original CancellationSource object.
requestCancellation Request cancellation of work associated with this CancellationSource.
swap Swaps the underlying state of the cancellation source with the source that is passed-in.

Static Member Functions

NameDescription
create Returns a pair of <CancellationSource, Data> where the underlying state is created using the arguments that is passed-in.
invalid Construct a CancellationSource that cannot be cancelled.

Friends

NameDescription
folly::operator==Return whether two sources share the same underlying cancellation state.

Non-Member Functions

NameDescription
operator!=Return whether two sources do not share the same underlying cancellation state.