Commit 023c64ff authored by Denis Bilenko's avatar Denis Bilenko

Hub.wait: use Waiter() to make it safer

parent c0be5c8a
......@@ -378,11 +378,12 @@ class Hub(greenlet):
raise AssertionError('Impossible to call blocking function in the event loop callback')
def wait(self, watcher):
waiter = Waiter()
unique = object()
watcher.start(getcurrent().switch, unique)
watcher.start(waiter.switch, unique)
try:
result = self.switch()
assert result is unique, 'Invalid switch into %s: %r' % (getcurrent(), result)
result = waiter.get()
assert result is unique, 'Invalid switch into %s: %r (expected %r)' % (getcurrent(), result, unique)
finally:
watcher.stop()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment