Skip to content

support both asyncio and blocking modes with different abstractions#178

Merged
achille-roussel merged 1 commit intoaiohttp-2from
asyncio-or-blocking
Jun 19, 2024
Merged

support both asyncio and blocking modes with different abstractions#178
achille-roussel merged 1 commit intoaiohttp-2from
asyncio-or-blocking

Conversation

@achille-roussel
Copy link
Contributor

Based on #176, this PR is an example of how we could change our internals to support both blocking and asyncio modes.

An important point here is we retain end-to-end type safety via annotations, since mypy is able to differentiate types (e.g., AsyncFunction and BlockingFunction).

@achille-roussel achille-roussel added enhancement New feature or request breaking change Breaking change that will be disruptive to programs that depended on them labels Jun 18, 2024
@achille-roussel achille-roussel self-assigned this Jun 18, 2024
Example:

import fastapi
from dispatch.asyncio.fastapi import Dispatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FastAPI wraps Starlette which is an ASGI framework. Should the asynchronous interface be the default for FastAPI (and should the user opt-in to the synchronous/blocking API)?

Copy link
Contributor Author

@achille-roussel achille-roussel Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked myself the same question... I know FastAPI is natively async, but their home page shows examples with non-async code (https://fastapi.tiangolo.com/), which makes me think it's probably a popular default.

The package name with asyncio is also self-explanatory, but using something like dispatch.blocking.fastapi would somewhat look like inventing a new name that may not be as clear to developers unfamiliar with the concept.

Tough call 🤷

@achille-roussel achille-roussel merged commit 41c6ad3 into aiohttp-2 Jun 19, 2024
@achille-roussel achille-roussel deleted the asyncio-or-blocking branch June 19, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Breaking change that will be disruptive to programs that depended on them enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants