Can I use an 'async-std' crate with 'tokio' by just importing it?


I'd like to use EdgeDB with tokio, but the client is created with async-std (a tokio version is planned).

I did some testing by importing the client and using it from within tokio and it seems to work.

However, I'm wondering if I could get into any troubles doing it this way. For example, it seems, if you want to go the opposite route, you have to use a compatibility layer (mostly because tokio is implemented in a certain way, it seems).

If doing it this way isn't recommended, how else could I use EdgeDB?

I don't care about performance, and I can live with pulling in async-std (for now). What I care most about, is ergonomics. So running async-std in a separate thread (and communicating with it via channels) wouldn't be great.

The async-std runtime is always global. This has some disadvantages (e.g. impossible to have multiple runtimes), but for your use-case it works out quite nicely. Any use of async-std primitives inside the Tokio runtime will be able to find the async-std runtime by looking at a global variable inside async-std.

The main place where something could go wrong is if you spawn something on the async-std runtime, as Tokio primitives wont be able to find the Tokio runtime from inside the async-std runtime.


Thank you, @alice, that sounds perfect.

Also thanks, for answering most of my questions. I think you are a great example to point to, when mentioning somewhere how amazing the Rust community is! :slight_smile:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.