Safe randomize using rand::thread_rng for selecting a random sample of members.
Concurrent selection of members in round 1 and 2.
Used tokio::sync::Mutex to share the data between threads in async.
P.S. For the folks who are beginners:
Don't give up.
I first tried with std::sync::Mutex and got it almost working but I struggled debug the final error where it said future cannot be sent between threads safely. Then I saw the hint in the linked article and used tokio::sync::Mutex to reimplement the solution.
I added below items:
rand::thread_rng
for selecting a random sample of members.tokio::sync::Mutex
to share the data between threads in async.P.S. For the folks who are beginners:
std::sync::Mutex
and got it almost working but I struggled debug the final error where it saidfuture cannot be sent between threads safely
. Then I saw the hint in the linked article and usedtokio::sync::Mutex
to reimplement the solution.