nomad
nomad

Reputation: 201

Is there a way to delay execution for a certain amount of time inside the body of a Rust async function?

I think std::thread::sleep(...) is not the right use case here.

Upvotes: 2

Views: 2231

Answers (1)

nomad
nomad

Reputation: 201

Using the tokio crate, there exists this function

tokio::time::delay_for(tokio::time::Duration::from_millis(WAIT_TIME_INTERVAL_MS));

That actually waits for Duration with any execution.

Upvotes: 2

Related Questions