Beispiel #1
0
    async def main():
        client = WSRPCClient("ws://127.0.0.1:8000/ws/", loop=loop)
        client.add_route('test', sleep)

        await client.connect()

        print(await client.call("test"))

        await client.close()
Beispiel #2
0
async def test_broadcast(client: WSRPCClient, handler: WebSocketAsync,
                         route: Route, loop):
    async with client:
        future = loop.create_future()

        async def on_broadcast(_, result):
            nonlocal future
            future.set_result(result)

        client.add_route("broadcast", on_broadcast)
        handler.add_route("reverse", route)

        await client.proxy.reverse(data=None)
        await asyncio.wait_for(client.proxy.reverse.broadcast(), timeout=999)

        assert await asyncio.wait_for(future, timeout=5)