Use async connect(...)

This commit is contained in:
Pedro Ferreira 2017-08-01 19:32:36 +02:00
parent 679cfb3fa1
commit 5c7888e006
3 changed files with 4 additions and 4 deletions

View File

@ -207,8 +207,8 @@ class PSClient(PSConnection):
self.connection.on_connect(self._on_connect) self.connection.on_connect(self._on_connect)
self.loop = loop self.loop = loop
def connect(self): async def connect(self):
self.connection.connect() await self.connection.connect()
class PSServer(PSConnection): class PSServer(PSConnection):

View File

@ -80,7 +80,7 @@ sign = SigningKey(server_prv_key[:32])
loop = get_event_loop() loop = get_event_loop()
packet_stream = PSClient('127.0.0.1', 8008, sign, server_pub_key, loop=loop) packet_stream = PSClient('127.0.0.1', 8008, sign, server_pub_key, loop=loop)
packet_stream.connect() loop.run_until_complete(packet_stream.connect())
api.add_connection(packet_stream) api.add_connection(packet_stream)
loop.run_until_complete(gather(ensure_future(api), main())) loop.run_until_complete(gather(ensure_future(api), main()))

View File

@ -15,7 +15,7 @@ with open(os.path.expanduser('~/.ssb/secret')) as f:
async def on_connect(): async def on_connect():
loop.create_task(ensure_future(packet_stream)) ensure_future(packet_stream, loop=loop)
# create console handler and set level to debug # create console handler and set level to debug
ch = logging.StreamHandler() ch = logging.StreamHandler()