Permalink
Browse files

add readypromise for compatibility

  • Loading branch information...
1 parent afa465b commit 58e7b4bb9effa883c52b7a0f39a830add5388647 @rep committed Dec 14, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 evnet/__init__.py
View
@@ -216,6 +216,7 @@ def __init__(self, addr, sock=None, cert=None):
self.buf = SSLbuf()
self._closed = False
self._writing = False
+ self._readypromise = Promise()
self.peerfp = None
self.readbytes = 0
self.writebytes = 0
@@ -293,8 +294,12 @@ def _sslshake(self, watcher=None, events=None):
pc = self.sslsock.get_peer_certificate()
self.peerfp = pc.digest('sha1').replace(':', '').lower()
self.read_watcher.start()
+ self._readypromise._resolve(self)
self._event('ready')
+ def onready(self):
+ return self._readypromise
+
def stop(self):
if self._closed:
raise EVException('Already closed.')
@@ -443,6 +448,7 @@ def __init__(self, addr, sock=None):
self.addr = addr
self.buf = bytearray()
+ self._readypromise = Promise()
self._closed = False
self._writing = False
@@ -466,6 +472,9 @@ def __init__(self, addr, sock=None):
self.initiate()
+ def onready(self):
+ return self._readypromise
+
def initiate(self):
raise EVException('Use subclass of Connection!')
@@ -476,6 +485,7 @@ def _connected(self, watcher=None, events=None):
if serr == 0:
hint(self.sock)
self.read_watcher.start()
+ self._readypromise._resolve(self)
self._event('ready')
else:
self._close('SO_ERROR: {0}'.format(errno.errorcode[serr]))
@@ -618,3 +628,6 @@ def tmpcaller():
self.aw.send()
r = q.get()
return r
+
+from .promise import Promise
+

0 comments on commit 58e7b4b

Please sign in to comment.