Skip to content

Instantly share code, notes, and snippets.

@BolajiOlajide
Created February 4, 2019 17:26
Show Gist options
  • Save BolajiOlajide/b004a4e8ec9b33d66a24d74d13485f96 to your computer and use it in GitHub Desktop.
Save BolajiOlajide/b004a4e8ec9b33d66a24d74d13485f96 to your computer and use it in GitHub Desktop.
import asyncio
# Borrowed from http://curio.readthedocs.org/en/latest/tutorial.html.
@asyncio.coroutine
def countdown(number, n):
while n > 0:
print('T-minus', n, '({})'.format(number))
yield from asyncio.sleep(1)
n -= 1
loop = asyncio.get_event_loop()
tasks = [
asyncio.ensure_future(countdown("A", 2)),
asyncio.ensure_future(countdown("B", 3))]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment