use tasks

This commit is contained in:
Luna Mendes 2017-12-03 16:32:31 -03:00
parent fce6a822e0
commit e7345520a8

View file

@ -73,7 +73,7 @@ async def send_msg(writer, op: int, data: str):
log.info('[send] %d, %s -> %r', op, data, msg) log.info('[send] %d, %s -> %r', op, data, msg)
writer.write(msg) writer.write(msg)
await writer.drain() asyncio.get_event_loop.create_task(writer.drain())
async def process(reader, writer, op: int, message: str): async def process(reader, writer, op: int, message: str):
@ -97,7 +97,7 @@ async def process(reader, writer, op: int, message: str):
async def handle_client(reader, writer): async def handle_client(reader, writer):
"""Handle clients""" """Handle clients"""
try: try:
await send_msg(writer, 0, 'hello') asyncio.get_event_loop().create_task(send_msg(writer, 0, 'hello'))
while True: while True:
op, message = await read_msg(reader) op, message = await read_msg(reader)