reactor: Support multiple waiting timers on a single completion

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-02-19 10:49:56 -05:00
parent 0e37f8c9b3
commit e3a5e2d271
1 changed files with 6 additions and 5 deletions

View File

@ -20,18 +20,19 @@ class ReactorCompletion:
def __init__(self, reactor):
self.reactor = reactor
self.result = self.sentinel
self.waiting = None
self.waiting = []
def test(self):
return self.result is not self.sentinel
def complete(self, result):
self.result = result
if self.waiting is not None:
self.reactor.update_timer(self.waiting.timer, self.reactor.NOW)
for wait in self.waiting:
self.reactor.update_timer(wait.timer, self.reactor.NOW)
def wait(self, waketime=_NEVER, waketime_result=None):
if self.result is self.sentinel:
self.waiting = greenlet.getcurrent()
wait = greenlet.getcurrent()
self.waiting.append(wait)
self.reactor.pause(waketime)
self.waiting = None
self.waiting.remove(wait)
if self.result is self.sentinel:
return waketime_result
return self.result