| 1483 | |
| 1484 | template <typename T> |
| 1485 | Result<AsyncGenerator<T>> MakeSequencedMergedGenerator( |
| 1486 | AsyncGenerator<AsyncGenerator<T>> source, int max_subscriptions) { |
| 1487 | if (max_subscriptions < 0) { |
| 1488 | return Status::Invalid("max_subscriptions must be a positive integer"); |
| 1489 | } |
| 1490 | if (max_subscriptions == 1) { |
| 1491 | return Status::Invalid("Use MakeConcatenatedGenerator if max_subscriptions is 1"); |
| 1492 | } |
| 1493 | AsyncGenerator<AsyncGenerator<T>> autostarting_source = MakeMappedGenerator( |
| 1494 | std::move(source), |
| 1495 | [](const AsyncGenerator<T>& sub) { return MakeAutoStartingGenerator(sub); }); |
| 1496 | AsyncGenerator<AsyncGenerator<T>> sub_readahead = |
| 1497 | MakeSerialReadaheadGenerator(std::move(autostarting_source), max_subscriptions - 1); |
| 1498 | return MakeConcatenatedGenerator(std::move(sub_readahead)); |
| 1499 | } |
| 1500 | |
| 1501 | /// \brief Create a generator that takes in a stream of generators and pulls from each |
| 1502 | /// one in sequence. |