I've a async method in my library that uses either file system or HTTP request to load external resources. However the HTTP request (reqwest) is failling because I'm awaiting it without Tokio's runtime:
match self._assets_load_via {
MessageLocatorLoadVia::FileSystem => {
...
},
MessageLocatorLoadVia::Http => {
...
for ... {
...
let content = reqwest::get(reqwest::Url::parse(res_path.clone().as_ref()).unwrap())
.await;
...
}
...
},
}
When I run code relying on this I'm getting:
thread 'msg_locator' panicked at 'there is no reactor running,
must be called from the context of a Tokio 1.x runtime',
C:\Users\hando\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.18.2\src\runtime\context.rs:21:19
Related dependencies:
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
How are you testing this library? The entry point must have either a #[tokio::main] annotation, #[tokio::test] annotation, or explicitly invoke the async functions within Runtime::block_on().