Skip to content

Instantly share code, notes, and snippets.

@petri
Last active September 28, 2020 14:28
Show Gist options
  • Save petri/a280f4dfef3f20d9c2edc2772fd74209 to your computer and use it in GitHub Desktop.
Save petri/a280f4dfef3f20d9c2edc2772fd74209 to your computer and use it in GitHub Desktop.
generic helper awaitable to synchronize awaiters chronologically on a first-come first-served basis
class bouncer(Awaitable):
"serve awaiters on a first-come first-served basis"
queue = []
def __init__(self):
type(self).queue.append(self.caller)
@property
def caller(self):
return current_task().get_coro()
def __await__(self):
while True:
if self.caller == type(self).queue[0]:
type(self).queue.pop(0)
return
else:
yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment