MCPcopy Create free account
hub / github.com/EmbodiedGPT/EmbodiedGPT_Pytorch / iter_over_async

Function iter_over_async

robohusky/utils.py:199–222  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

197
198
199def 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
225def detect_language(text: str) -> str:

Callers

nothing calls this directly

Calls 1

get_nextFunction · 0.85

Tested by

no test coverage detected