[svn r111] add ready() method to event class, so you can tell in advance whether or not wait() is going to block.

This commit is contained in:
q.linden
2008-05-06 13:45:59 -04:00
parent 22226ece2b
commit cc2c94ab7b

View File

@@ -95,6 +95,14 @@ class event(object):
self.epoch = time.time()
self._result = NOT_USED
self._waiters = {}
def ready(self):
""" Return true if the wait() call will return immediately.
Used to avoid waiting for things that might take a while to time out.
For example, you can put a bunch of events into a list, and then visit
them all repeatedly, calling ready() until one returns True, and then
you can wait() on that one."""
return self._result is not NOT_USED
def wait(self):
"""Wait until another coroutine calls send.