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

Maybe use sniffio to implement generic run_service and backgorund_service methods. #18

Open
pipermerriam opened this issue Dec 13, 2019 · 1 comment

Comments

@pipermerriam
Copy link
Member

What is wrong

The Service API is currently totally agnostic to whether things are trio/asyncio. This is good.

The Manager API is also totally agnostic to whether things are trio/asyncio, however you do have to use the right manager for any given async framework. Basically, ignoring how you acquire a manager instance, the same code can work with both asyncio/trio.

The running of services is not agnostic. You're required to pick run_asyncio_service or run_trio_service. Same with backgorund_asyncio_service and background_trio_service.

It would be ideal to expose simple run_service and background_service APIs that could be used in either async framework.

How can it be fixed

I think we can pretty easily use sniffio to create these generic apis. I'm not seeing an obvious downside and sniffio is an incredibly simple and small library.

@staccDOTsol
Copy link

Thank you for your suggestion. Using sniffio to implement generic run_service and background_service methods is indeed a great idea. By leveraging sniffio, we can create APIs that are agnostic to whether the underlying async framework is trio or asyncio.

With sniffio, we can detect the currently running async framework and dynamically choose the appropriate implementation for running services. This would allow developers to write code that works seamlessly with both trio and asyncio without having to worry about the specific framework being used.

I will definitely consider this approach and explore the possibilities of implementing it in the Ethereum codebase. Thank you for bringing this to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants