| 1 |
/* |
| 2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <folly/experimental/coro/Coroutine.h> |
| 18 |
|
| 19 |
namespace folly { |
| 20 |
namespace coro { |
| 21 |
|
| 22 |
template < |
| 23 |
typename HReference, |
| 24 |
typename... TReference, |
| 25 |
typename HValue, |
| 26 |
typename... TValue> |
| 27 |
AsyncGenerator<HReference, HValue> concat( |
| 28 |
AsyncGenerator<HReference, HValue> head, |
| 29 |
AsyncGenerator<TReference, TValue>... tail) { |
| 30 |
static_assert((std::is_same_v<decltype(head), decltype(tail)> && ...)); |
| 31 |
using list = AsyncGenerator<HReference, HValue>[]; |
| 32 |
for (auto& gen : list{std::move(head), std::move(tail)...}) { |
| 33 |
while (auto val = co_await gen.next()) { |
| 34 |
co_yield std::move(val).value(); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
} // namespace coro |
| 40 |
} // namespace folly |