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:
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.
Based on #122, this PR adds a new integration with the
aiohttp
framework, to enable dispatch applications that run onaiohttp
servers, or useaiohttp
clients to integrate with theasyncio
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:This would cause a call to
job
to be dispatched to the scheduler, then waited on by thedispatch.run
event loop, with the result returned.This could also be composed with other
asyncio
operations: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!