Skip to content
Myr

concurrency.py

This file

Path

tests/concurrency.py

31 lines · 685 bytes · Python

Last changed by

Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6

History of this file

Take it

1"""2This module contains concurrency utilities that are only used in tests, thus not3required as part of the ConcurrencyBackend API.4"""56import asyncio7import functools89from httpx import AsyncioBackend101112@functools.singledispatch13async def sleep(backend, seconds: int):14    raise NotImplementedError  # pragma: no cover151617@sleep.register(AsyncioBackend)18async def _sleep_asyncio(backend, seconds: int):19    await asyncio.sleep(seconds)202122try:23    import trio24    from httpx.concurrency.trio import TrioBackend25except ImportError:  # pragma: no cover26    pass27else:2829    @sleep.register(TrioBackend)30    async def _sleep_trio(backend, seconds: int):31        await trio.sleep(seconds)