Skip to content

Commit

Permalink
Merge f28f6c9 into e70324e
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1l committed Aug 1, 2017
2 parents e70324e + f28f6c9 commit c7295f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 8 additions & 6 deletions secret_handshake/boxstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ async def read(self):
self.nonce = inc_nonce(inc_nonce(self.nonce))
return body

async def __aiter__(self):
while True:
data = await self.read()
if data is None:
return
yield data
def __aiter__(self):
return self

async def __anext__(self):
data = await self.read()
if data is None:
raise StopAsyncIteration
return data


class BoxStream(object):
Expand Down
12 changes: 9 additions & 3 deletions secret_handshake/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ async def read(self):
def disconnect(self):
self.writer.close()

async def __aiter__(self):
async for msg in self.read_stream:
yield msg
def __aiter__(self):
return self

async def __anext__(self):
msg = self.read_stream
if msg:
return msg
else:
raise StopAsyncIteration

def on_connect(self, cb):
self._on_connect = cb
Expand Down

0 comments on commit c7295f4

Please sign in to comment.