Starts and later joins a dynamic, unbounded set of concurrent tasks.
Declared in <folly/coro/AsyncScope.h>
class AsyncScope;
The AsyncScope class is used to allow you to start a dynamic, unbounded number of tasks, which can all run concurrently, and then later wait for completion of all of the tasks.
Tasks added to an AsyncScope must have a void or folly::Unit result-type and must handle any errors prior to completing.
Example:
folly::coro::Task<void> process(Event event) {
try {
co_await do_processing(event.data);
} catch (...) {
LOG(ERROR) << "Processing event failed";
}
}
folly::coro::AsyncScope scope;
scope.add(co_withExecutor(folly::getGlobalCPUExecutor(), process(ev1)));
scope.add(co_withExecutor(folly::getGlobalCPUExecutor(), process(ev2)));
scope.add(co_withExecutor(folly::getGlobalCPUExecutor(), process(ev3)));
co_await scope.joinAsync();
refcode folly/docs/examples/folly/coro/AsyncScope.cpp
| Name | Description |
|---|---|
AsyncScope [constructor] | Constructs an empty scope with no started tasks. |
~AsyncScope [destructor] | Destroy the AsyncScope object. |
add | Start the specified task/awaitable by co_awaiting it. |
addWithSourceLoc | Like add(), but records the call-site source location for diagnostics. |
cleanup | Asynchronously cleanup all started tasks. |
joinAsync | Asynchronously wait for all started tasks to complete. |
remaining | Query the number of tasks added to the scope that have not yet completed. |
| Name | Description |
|---|---|
makeUnorderedAsyncGenerator | Yield the results of a vector of awaitables in order of completion. |
makeUnorderedAsyncGenerator | Yield the results of a range of awaitables in order of completion. |
makeUnorderedTryAsyncGenerator | Yield Try results of a vector of awaitables in order of completion. |
makeUnorderedTryAsyncGenerator | Yield Try results of a range of awaitables in order of completion. |