Merge takes a list of receivers, and returns a new receiver that receives all updates from all input receivers. If any input receiver closes with an exception, the exception is forwarded and the channel is closed. If any input receiver closes without an exception, the channel continues to merge values from the other input receivers until all input receivers are closed.
Declared in <folly/channels/Merge.h>
template<
typename TReceiver,
typename TValue = TReceiver::ValueType>
Receiver<TValue>
merge(
std::vector<TReceiver> inputReceivers,
folly::Executor::KeepAlive<folly::SequencedExecutor> executor,
bool waitForAllInputsToClose = true);
Example:
// Example function that returns a list of receivers std::vector<Receiver<int>> getReceivers();
// Example function that returns an executor folly::Executor::KeepAlive<folly::SequencedExecutor> getExecutor();
Receiver<int> mergedReceiver = merge(getReceivers(), getExecutor());
A receiver that yields all values from every input receiver.
| Name | Description |
|---|---|
| inputReceivers | The collection of input receivers to merge. |
| executor | A SequencedExecutor used to merge input values. |
| waitForAllInputsToClose | When true, if any input receiver closes without an exception, the channel continues to merge values from the other input receivers until all input receivers are closed. If false, the channel closes as soon as any input receiver has closed. |