This function takes a Receiver, and consumes updates from that receiver with a callback.
Synopsis
Declared in <folly/channels/ConsumeChannel.h>
template<
typename TReceiver,
typename OnNextFunc,
typename TValue = TReceiver::ValueType>
requires std::constructible_from<
folly::Function<folly::coro::Task<bool>(Try<TValue>)>,
OnNextFunc>
ChannelCallbackHandle
consumeChannelWithCallback(
TReceiver receiver,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
OnNextFunc onNext);
Description
This function returns a ChannelCallbackHandle. On destruction of this handle, the callback will receive a try containing an exception of type folly::OperationCancelled. If an active callback is running at the time the cancellation request is received, cancellation will be requested on the ambient cancellation token of the callback.
The callback is run for each received value on the given executor. A try is passed to the callback with the result:
-
If a value is sent, the Try will contain the value.
-
If the channel is closed by the sender with no exception, the try will be empty (with no value or exception).
-
If the channel is closed by the sender with an exception, the try will contain the exception.
-
If the channel was cancelled (by the destruction of the returned handle), the try will contain an exception of type folly::OperationCancelled.
If the callback returns false or throws a folly::OperationCancelled exception, the channel will be cancelled and no further values will be received.
Return Value
A handle that cancels the consumption operation when destroyed.
Parameters
Name |
Description |
receiver |
The receiver whose values are consumed. |
executor |
The executor on which each callback invocation runs. |
onNext |
The callback invoked for each received value. |
Created with MrDocs