Convert async generator to sync generator :param async_gen: the AsyncGenerator to convert :param event_loop: the event loop to run on :returns: Sync generator
(
async_gen: AsyncGenerator, event_loop: AbstractEventLoop
)
| 197 | |
| 198 | |
| 199 | def iter_over_async( |
| 200 | async_gen: AsyncGenerator, event_loop: AbstractEventLoop |
| 201 | ) -> Generator: |
| 202 | """ |
| 203 | Convert async generator to sync generator |
| 204 | |
| 205 | :param async_gen: the AsyncGenerator to convert |
| 206 | :param event_loop: the event loop to run on |
| 207 | :returns: Sync generator |
| 208 | """ |
| 209 | ait = async_gen.__aiter__() |
| 210 | |
| 211 | async def get_next(): |
| 212 | try: |
| 213 | obj = await ait.__anext__() |
| 214 | return False, obj |
| 215 | except StopAsyncIteration: |
| 216 | return True, None |
| 217 | |
| 218 | while True: |
| 219 | done, obj = event_loop.run_until_complete(get_next()) |
| 220 | if done: |
| 221 | break |
| 222 | yield obj |
| 223 | |
| 224 | |
| 225 | def detect_language(text: str) -> str: |
nothing calls this directly
no test coverage detected