endpoints icon indicating copy to clipboard operation
endpoints copied to clipboard

Asyncio interfaces

Open Jaymon opened this issue 2 years ago • 2 comments

Now that python2 support has been dropped I think I will add asyncio support with the ASGI interface. After some tests, it looks like I can have the async and sync interfaces be the same, the sync will just extend the async interface and wrap all the methods, something like:

class AsyncFoo(object):
    async def foo(self, ret_value, sleep=1):
        print("async")
        await asyncio.sleep(sleep)
        print("foo")
        return value


class SyncFoo(AsyncFoo):
    def foo(self, *args, **kwargs):
        return asyncio.run(super().foo(*args, **kwargs))


f = SyncFoo()
print(f.foo(6))

This works in my tests and so, hopefully, something similar to my tests will actually work when implemented so I can keep the interfaces the same and then it's just a choice on what to use.

Links I had open

Search

  • does python asyncio need monkey patching
  • python async

Jaymon avatar Oct 10 '21 20:10 Jaymon