-
Notifications
You must be signed in to change notification settings - Fork 40
Asyncio
Beau Barker edited this page Jul 3, 2025
·
3 revisions
"""Demonstrates processing a batch of 100 requests asynchronously with asyncio.""" import asyncio import json
from jsonrpcserver import Result, Success, async_dispatch, method
@method async def sleep_() -> Result: """JSON-RPC method""" await asyncio.sleep(1) return Success()
async def handle(req: str) -> None: """Handle asyncio event""" print(await async_dispatch(req))
if name == "main": request = json.dumps( [{"jsonrpc": "2.0", "method": "sleep_", "id": 1} for _ in range(100)] ) asyncio.get_event_loop().run_until_complete(handle(request))
Contributions are appreciated – simply hit Edit or New page.