Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interoperability with asyncio (part 2): integration with aiohttp #175

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

achille-roussel
Copy link
Contributor

Based on #122, this PR adds a new integration with the aiohttp framework, to enable dispatch applications that run on aiohttp servers, or use aiohttp clients to integrate with the asyncio facilities end-to-end.

This change is also a prerequisite to more modifications I want to bring to the SDK, that in my mind are other prerequisites for a sync mode where we can wait on dispatch calls in retrieve their results.

Thoughts on next steps

What I would like to get to is an API that matches asyncio more closely, for example:

import dispatch

@dispatch.function
async def job():
    ...

dispatch.run(job())

This would cause a call to job to be dispatched to the scheduler, then waited on by the dispatch.run event loop, with the result returned.

This could also be composed with other asyncio operations:

import dispatch

@dispatch.function
async def job():
    ...

async def main():
    # dispatch.sdk.v1.DispatchServer/Dispatch because not in the context
    # of a dispatch function, then poll for the result
    return await job() 

dispatch.run(main())

This would provide a unified model for both durable and volatile contexts, which would pave the road to simple testing constructs, examples, and integrations with RPC handlers etc...

For blocking world that doesn't use asyncio, the .dispatch() method can still be used, but we'd modify its return value to a form of future-like value where the result can be retrieved in a blocking fashion.

Let me know what you think!

Signed-off-by: Achille Roussel <[email protected]>
@achille-roussel achille-roussel added the enhancement New feature or request label Jun 4, 2024
@achille-roussel achille-roussel self-assigned this Jun 4, 2024
Signed-off-by: Achille Roussel <[email protected]>
Base automatically changed from asyncio to main June 5, 2024 17:24
@achille-roussel achille-roussel merged commit 6661a09 into main Jun 5, 2024
7 checks passed
@achille-roussel achille-roussel deleted the aiohttp branch June 5, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants