| 1589 | |
| 1590 | template <typename T> |
| 1591 | Result<AsyncGenerator<T>> MakeSequencedMergedGenerator( |
| 1592 | AsyncGenerator<AsyncGenerator<T>> source, int max_subscriptions) { |
| 1593 | if (max_subscriptions < 0) { |
| 1594 | return Status::Invalid("max_subscriptions must be a positive integer"); |
| 1595 | } |
| 1596 | if (max_subscriptions == 1) { |
| 1597 | return Status::Invalid("Use MakeConcatenatedGenerator if max_subscriptions is 1"); |
| 1598 | } |
| 1599 | AsyncGenerator<AsyncGenerator<T>> autostarting_source = MakeMappedGenerator( |
| 1600 | std::move(source), |
| 1601 | [](const AsyncGenerator<T>& sub) { return MakeAutoStartingGenerator(sub); }); |
| 1602 | AsyncGenerator<AsyncGenerator<T>> sub_readahead = |
| 1603 | MakeSerialReadaheadGenerator(std::move(autostarting_source), max_subscriptions - 1); |
| 1604 | return MakeConcatenatedGenerator(std::move(sub_readahead)); |
| 1605 | } |
| 1606 | |
| 1607 | /// \brief Create a generator that takes in a stream of generators and pulls from each |
| 1608 | /// one in sequence. |