api.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:masters 作者: zaibacu 项目源码 文件源码
def ws_handler(request):
    ws = web.WebSocketResponse(timeout=60)
    await ws.prepare(request)

    pipeline = iter([validate_token, load_score])

    async for msg in ws:
        cmd = next(pipeline)
        if msg.tp == aiohttp.MsgType.text:
            if msg == "close":
                await ws.close()
            else:
                result, msg = await cmd(msg.data)
                ws.send_str(msg)
                if not result:
                    await ws.close()
                    break

        elif msg.tp == aiohttp.MsgType.error:
            handle_error(ws)

    return ws
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号