Skip to content

Instantly share code, notes, and snippets.

@volosati
volosati / loop_hack.py
Created March 28, 2022 01:24 — forked from erikbern/loop_hack.py
Example of how to use async/await programming in Python for non-asyncio purposes
# First, let's create an awaitable object.
# In this case it's a very dumb container of integers.
# Any time a coroutine runs `await Thing(n)` it just resolves to n
# However, we could resolve it to something completely different if we wanted to
class Thing:
def __init__(self, n):
self._n = n
def __await__(self):