aboutsummaryrefslogtreecommitdiff
path: root/core/src/async_util/condwait.rs
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-29 21:16:46 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-29 21:16:46 +0200
commit5c0abab1b7bf0f2858c451d6f0efc7ca0e138fc6 (patch)
tree9d64a261ddd289560365b71f5d02d31df6c4a0ec /core/src/async_util/condwait.rs
parentbcc6721257889f85f57af1b40351540585ffd41d (diff)
use shadown variables to name clones and place them between {} when spawning new tasks
Diffstat (limited to 'core/src/async_util/condwait.rs')
-rw-r--r--core/src/async_util/condwait.rs52
1 files changed, 30 insertions, 22 deletions
diff --git a/core/src/async_util/condwait.rs b/core/src/async_util/condwait.rs
index 76c6a05..b96d979 100644
--- a/core/src/async_util/condwait.rs
+++ b/core/src/async_util/condwait.rs
@@ -13,10 +13,12 @@ use crate::async_runtime::lock::Mutex;
///
/// async {
/// let cond_wait = Arc::new(CondWait::new());
-/// let cond_wait_cloned = cond_wait.clone();
-/// let task = spawn(async move {
-/// cond_wait_cloned.wait().await;
-/// // ...
+/// let task = spawn({
+/// let cond_wait = cond_wait.clone();
+/// async move {
+/// cond_wait.wait().await;
+/// // ...
+/// }
/// });
///
/// cond_wait.signal().await;
@@ -91,12 +93,14 @@ mod tests {
let cond_wait = Arc::new(CondWait::new());
let count = Arc::new(AtomicUsize::new(0));
- let cond_wait_cloned = cond_wait.clone();
- let count_cloned = count.clone();
- let task = spawn(async move {
- cond_wait_cloned.wait().await;
- count_cloned.fetch_add(1, Ordering::Relaxed);
- // do something
+ let task = spawn({
+ let cond_wait = cond_wait.clone();
+ let count = count.clone();
+ async move {
+ cond_wait.wait().await;
+ count.fetch_add(1, Ordering::Relaxed);
+ // do something
+ }
});
// Send a signal to the waiting task
@@ -109,20 +113,24 @@ mod tests {
assert_eq!(count.load(Ordering::Relaxed), 1);
- let cond_wait_cloned = cond_wait.clone();
- let count_cloned = count.clone();
- let task1 = spawn(async move {
- cond_wait_cloned.wait().await;
- count_cloned.fetch_add(1, Ordering::Relaxed);
- // do something
+ let task1 = spawn({
+ let cond_wait = cond_wait.clone();
+ let count = count.clone();
+ async move {
+ cond_wait.wait().await;
+ count.fetch_add(1, Ordering::Relaxed);
+ // do something
+ }
});
- let cond_wait_cloned = cond_wait.clone();
- let count_cloned = count.clone();
- let task2 = spawn(async move {
- cond_wait_cloned.wait().await;
- count_cloned.fetch_add(1, Ordering::Relaxed);
- // do something
+ let task2 = spawn({
+ let cond_wait = cond_wait.clone();
+ let count = count.clone();
+ async move {
+ cond_wait.wait().await;
+ count.fetch_add(1, Ordering::Relaxed);
+ // do something
+ }
});
// Broadcast a signal to all waiting tasks