Last active
September 28, 2020 14:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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