You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::thread::sleep;use std::time::Duration;use futures::FutureExt;use futures::executor::ThreadPool;asyncfncpu_intensive(i:u64){letmut res:u64 = 0;for j in0..23{for k in0..256{
res += j + i + k;
res %= 91349;}// Imagine that here an async API call is required, so we want another future to continue while this future is waiting for the API result }println!("{}: {}", i, res)}fnmain(){let pool = ThreadPool::new().unwrap();for i in0..1000{let fut = cpu_intensive(i);
pool.spawn_ok(fut)}// NEEDED: A way to wait for the thread pool to run until completionsleep(Duration::from_secs(2));}
It would be great if there was a way to block main until all futures of the ThreadPool are completed.
The text was updated successfully, but these errors were encountered:
Consider the following example for the threadpool, which is close to the example from the documentation:
https://docs.rs/futures/0.3.15/futures/executor/struct.ThreadPool.html
It would be great if there was a way to block main until all futures of the ThreadPool are completed.
The text was updated successfully, but these errors were encountered: