 <p>In Python 3.5, the <code>async for</code> syntax is introduced. However, asynchronous iterator function syntax is still absent (i.e. <code>yield</code> is prohibited in <code>async</code> functions). Here's a workaround:</p> <pre><code>import asyncio import inspect class escape(object): def __init__(self, value): self.value = value class _asynciter(object): def __init__(self, iterator): self.itr = iterator async def __aiter__(self): return self async def __anext__(self): try: yielded = next(self.itr) while inspect.isawaitable(yielded): try: result = await yielded except Exception as e: yielded = self.itr.throw(e) else: yielded = self.itr.send(result) else: if isinstance(yielded, escape): return yielded.value else: return yielded except StopIteration: raise StopAsyncIteration def asynciter(f): return lambda *arg, **kwarg: _asynciter(f(*arg, **kwarg)) </code></pre> <p>Then your code could be written as:</p> <pre><code>@asynciter def countdown(n): while n &gt; 0: yield from asyncio.sleep(1) #or: #yield asyncio.sleep(1) n = n - 1 yield n async def do_work(): async for n in countdown(5): print(n) asyncio.get_event_loop().run_until_complete(do_work()) </code></pre> <p>To learn about the new syntax, and how this code works, see <a href="https://www.python.org/dev/peps/pep-0492/#asynchronous-iterators-and-async-for" rel="nofollow">PEP 492</a></p>