@@ -31,26 +31,16 @@ pub struct CountDownLatch {
31
31
}
32
32
33
33
impl CountDownLatch {
34
- /// Creates a new `CountDownLatch` initialized with the given count.
35
- ///
36
- /// # Arguments
37
- ///
38
- /// * `count` - The number of times `count_down` must be invoked before tasks can pass through
39
- /// `wait`.
40
- ///
41
- /// # Returns
42
- ///
43
34
/// A new `CountDownLatch`.
35
+ #[ inline]
44
36
pub fn new ( count : u32 ) -> Self {
45
37
CountDownLatch {
46
38
count : Arc :: new ( Mutex :: new ( count) ) ,
47
39
notify : Arc :: new ( Notify :: new ( ) ) ,
48
40
}
49
41
}
50
42
51
- /// Decrements the count of the latch, releasing all waiting tasks if the count reaches zero.
52
- ///
53
- /// This method is asynchronous and will lock the internal count before decrementing it.
43
+ #[ inline]
54
44
pub async fn count_down ( & self ) {
55
45
let mut count = self . count . lock ( ) . await ;
56
46
* count -= 1 ;
@@ -59,9 +49,7 @@ impl CountDownLatch {
59
49
}
60
50
}
61
51
62
- /// Waits until the count reaches zero.
63
- ///
64
- /// This method is asynchronous and will block the current task until the count reaches zero.
52
+ #[ inline]
65
53
pub async fn wait ( & self ) {
66
54
let count = self . count . lock ( ) . await ;
67
55
if * count > 0 {
@@ -70,18 +58,7 @@ impl CountDownLatch {
70
58
}
71
59
}
72
60
73
- /// Waits until the count reaches zero or the specified timeout elapses.
74
- ///
75
- /// This method is asynchronous and will block the current task until the count reaches zero
76
- /// or the timeout elapses.
77
- ///
78
- /// # Arguments
79
- ///
80
- /// * `timeout` - The maximum duration to wait for the count to reach zero.
81
- ///
82
- /// # Returns
83
- ///
84
- /// `true` if the count reached zero before the timeout elapsed, `false` otherwise.
61
+ #[ inline]
85
62
pub async fn wait_timeout ( & self , timeout : Duration ) -> bool {
86
63
tokio:: time:: timeout ( timeout, self . wait ( ) ) . await . is_ok ( )
87
64
}
0 commit comments