CodexBloom - Programming Q&A Platform

Using `async-std` with `tokio` results in runtime panic when mixing async contexts

πŸ‘€ Views: 70 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-01
rust async-await tokio async-std Rust

I've searched everywhere and can't find a clear answer. I'm confused about After trying multiple solutions online, I still can't figure this out. I have a Rust application where I'm trying to use `async-std` for some parts and `tokio` for others. However, when I run a function that uses `async-std` within a `tokio` runtime, I encounter a panic that says: `thread 'main' panicked at 'future want to be polled without a context'`. Here’s a simplified version of my code: ```rust use async_std::task; use tokio::runtime::Runtime; fn async_std_function() { task::block_on(async { println!("Running async-std function"); }); } fn main() { let rt = Runtime::new().unwrap(); rt.block_on(async { async_std_function(); }); } ``` I initially thought mixing both runtimes might work since they are both async, but it seems like I'm running into issues with contexts. I’ve tried wrapping the `async_std_function` in a `tokio::task::spawn`, but it still leads to the same panic. Is there a way to effectively use both `async-std` and `tokio` together in the same application without running into context issues? Any best practices or recommendations would be greatly appreciated. This issue appeared after updating to Rust 3.9. I'm coming from a different tech stack and learning Rust. Any ideas how to fix this? My development environment is Ubuntu 20.04. Could someone point me to the right documentation?