Tokio error: "there is no reactor running" even with #[tokio::main] and a single version of tokio installed

when running code like this:

use futures::executor;
...
pub fn store_temporary_password(email: &str, password: &str) -> Result<(), Box<dyn Error>> {
  let client = DynamoDbClient::new(Region::ApSoutheast2);
  ...
  let future = client.put_item(input);
  executor::block_on(future)?; <- crashes here
  Ok(())
}

I get the error:

thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime

My main has the tokio annotation as it should:

#[tokio::main]
async fn main() {
  ...

My cargo.toml looks like:

[dependencies]
...
futures = { version="0", features=["executor"] }
tokio = "1"

My cargo.lock shows that i only have 1 version of both futures and tokio ("1.2.0" and "0.3.12" respectively).

This exhausts the explanations I found elsewhere for this problem. Any ideas? Thanks.



Read more here: https://stackoverflow.com/questions/66328113/tokio-error-there-is-no-reactor-running-even-with-tokiomain-and-a-single

Content Attribution

This content was originally published by Chris at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: