A cancellable version of AsyncScope. Work added to this scope will be provided a cancellation token for cancelling during join.

Synopsis

Declared in <folly/coro/AsyncScope.h>

class CancellableAsyncScope;

Description

See add() and cancelAndJoinAsync() for more information.

Note: Task and AsyncGenerator will ignore the internal cancellation signal if they already have a cancellation token (i.e. if someone has already called co_withCancellation on them.) If you need an external cancellation signal as well, pass that token to this constructor or to add() instead of attaching it to the Awaitable.

refcode folly/docs/examples/folly/coro/CancellableAsyncScope.cpp

Member Functions

Name

Description

CancellableAsyncScope [constructor]

Constructors

add

Start the specified task/awaitable by co_awaiting it. The awaitable will be provided a cancellation token to respond to cancelAndJoinAsync() in the future.

addWithSourceLoc

Like add(), but records the call‐site source location for diagnostics.

cancelAndJoinAsync

Request cancellation and asynchronously wait for all started tasks to complete.

co_schedule

Schedules the given task on the current executor and adds it to the AsyncScope. The task will be provided a cancellation token to respond to cancelAndJoinAsync() in the future.

isScopeCancellationRequested

Query if cancellation was requested on the tasks added to this AsyncScope.

joinAsync

Asynchronously wait for all started tasks to complete without requesting cancellation.

remaining

Query the number of tasks added to the scope that have not yet completed.

requestCancellation

Request cancellation for all started tasks that accepted a CancellationToken in add().

Non-Member Functions

Name

Description

makeUnorderedAsyncGenerator

Yield the results of a range of awaitables in order of completion.

makeUnorderedAsyncGenerator

Yield the results of a vector of awaitables in order of completion.

makeUnorderedTryAsyncGenerator

Yield Try results of a range of awaitables in order of completion.

makeUnorderedTryAsyncGenerator

Yield Try results of a vector of awaitables in order of completion.

Created with MrDocs