Commit 939cb70b authored by Denis Bilenko's avatar Denis Bilenko

Event: rename link to rawlink and make it not create an auxilary greenlet

parent c435b2fa
...@@ -19,10 +19,12 @@ class Event(object): ...@@ -19,10 +19,12 @@ class Event(object):
if self._value is not _NONE: if self._value is not _NONE:
return self._value return self._value
def link(self, callback): def rawlink(self, callback):
if self._value is _NONE: if self._value is _NONE:
self._links.add(callback) self._links.add(callback)
else: else:
# QQQ switch won't work as a callback!
# QQQ should I schedule the callback here too, like Greenlet.rawlink does?
callback(self) callback(self)
def unlink(self, callback): def unlink(self, callback):
...@@ -43,9 +45,8 @@ class Event(object): ...@@ -43,9 +45,8 @@ class Event(object):
assert getcurrent() is get_hub() assert getcurrent() is get_hub()
while self._links: while self._links:
link = self._links.pop() link = self._links.pop()
g = greenlet(link)
try: try:
g.switch(self) link(self)
except: except:
traceback.print_exc() traceback.print_exc()
try: try:
...@@ -59,7 +60,7 @@ class Event(object): ...@@ -59,7 +60,7 @@ class Event(object):
return self._value return self._value
elif block: elif block:
switch = getcurrent().switch switch = getcurrent().switch
self.link(switch) self.rawlink(switch)
try: try:
# result = None # result = None
# if not isinstance(timeout, Timeout): # need Timeout.start() method to implement this # if not isinstance(timeout, Timeout): # need Timeout.start() method to implement this
...@@ -85,7 +86,7 @@ class Event(object): ...@@ -85,7 +86,7 @@ class Event(object):
return return
else: else:
switch = getcurrent().switch switch = getcurrent().switch
self.link(switch) self.rawlink(switch)
try: try:
t = Timeout(timeout) t = Timeout(timeout)
try: try:
...@@ -157,7 +158,7 @@ def waitall(events): ...@@ -157,7 +158,7 @@ def waitall(events):
put = queue.put put = queue.put
try: try:
for event in events: for event in events:
event.link(put) event.rawlink(put)
for _ in xrange(len(events)): for _ in xrange(len(events)):
queue.get() queue.get()
finally: finally:
......
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