Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use slots

  • Loading branch information...
commit 5cf82a076811c61cf21a9793e9c4b09e5c1d0599 1 parent 6dc6767
Alvaro authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 evy/event.py
View
16 evy/event.py
@@ -32,14 +32,19 @@
from evy import hubs
from evy.support import greenlets as greenlet
+
__all__ = ['Event']
+
class NOT_USED:
def __repr__ (self):
return 'NOT_USED'
NOT_USED = NOT_USED()
+
+
+
class Event(object):
"""
An abstraction where an arbitrary number of coroutines can wait for one event from another.
@@ -58,13 +63,16 @@ class Event(object):
>>> def baz(b):
... evt.send(b + 1)
...
- >>> _ = evy.spawn_n(baz, 3)
+ >>> _ = spawn_n(baz, 3)
>>> evt.wait()
4
"""
+
+ __slots__ = ['_result', '_exc', '_waiters']
_result = None
_exc = None
+
def __init__ (self):
self._waiters = set()
self.reset()
@@ -132,7 +140,7 @@ def wait (self):
... print "waited for", retval
>>> _ = evy.spawn(wait_on)
>>> evt.send('result')
- >>> evy.sleep(0)
+ >>> sleep(0)
waited for result
Returns immediately if the event has already
@@ -165,10 +173,10 @@ def send (self, result = None, exc = None):
... result = evt.wait()
... print 'waited for', result
>>> _ = evy.spawn(waiter)
- >>> evy.sleep(0)
+ >>> sleep(0)
about to wait
>>> evt.send('a')
- >>> evy.sleep(0)
+ >>> sleep(0)
waited for a
It is an error to call :meth:`send` multiple times on the same event.
Please sign in to comment.
Something went wrong with that request. Please try again.