Usually in IO operations we use iter() to read up to sentinel value:
from sys import stdout
with open(r"Z:\github\StackOverFlow\temp.json", "r") as fp:
for chunk in iter(lambda :fp.read(64), ""):
stdout.write(chunk)
But is there alternative to iter() for awaitable, i.e. asyncio.Queue.get()?
for val in iter(lambda: await queue.get(), sentinel):
queue.task_done()
print(val)
Surely this won't work as while it requires callable, await can't be called inside non-async functions.
Situation does not allow queue.get_nowait() as queue is empty for most of time.
Simple fix would be using while loop:
while True:
if (val := await queue.get()) is None:
break
queue.task_done()
print(val)
But I'm afraid if this harms readability and clarity.