@@ -118,6 +118,18 @@ impl OnceTrigger {
118
118
pub fn trigger ( self ) -> bool {
119
119
self . 0 . send ( ( ) ) . is_ok ( )
120
120
}
121
+
122
+ pub async fn dropped ( & mut self ) {
123
+ self . 0 . closed ( ) . await
124
+ }
125
+
126
+ pub fn is_dropped ( & self ) -> bool {
127
+ self . 0 . is_closed ( )
128
+ }
129
+
130
+ pub fn poll_dropped ( & mut self , cx : & mut Context < ' _ > ) -> Poll < ( ) > {
131
+ self . 0 . poll_closed ( cx)
132
+ }
121
133
}
122
134
123
135
#[ derive( Default , Debug , Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -242,6 +254,42 @@ mod tests {
242
254
assert_eq ! ( waiter. has_been_triggered( ) , Triggered :: Dropped ) ;
243
255
}
244
256
257
+ #[ test]
258
+ fn is_dropped ( ) {
259
+ let ( trigger, waiter) = once_event ( ) ;
260
+ assert ! ( !trigger. is_dropped( ) ) ;
261
+ drop ( waiter) ;
262
+ assert ! ( trigger. is_dropped( ) ) ;
263
+ }
264
+
265
+ #[ tokio:: test( flavor = "multi_thread" ) ]
266
+ async fn dropped ( ) {
267
+ let ( mut trigger, waiter) = once_event ( ) ;
268
+ assert ! ( !trigger. is_dropped( ) ) ;
269
+
270
+ tokio:: spawn ( async move {
271
+ drop ( waiter) ;
272
+ } ) ;
273
+
274
+ trigger. dropped ( ) . await ;
275
+ assert ! ( trigger. is_dropped( ) ) ;
276
+ }
277
+
278
+ #[ tokio:: test( flavor = "multi_thread" ) ]
279
+ async fn poll_dropped ( ) {
280
+ use std:: future:: poll_fn;
281
+
282
+ let ( mut trigger, waiter) = once_event ( ) ;
283
+ assert ! ( !trigger. is_dropped( ) ) ;
284
+
285
+ tokio:: spawn ( async move {
286
+ drop ( waiter) ;
287
+ } ) ;
288
+
289
+ poll_fn ( |cx| trigger. poll_dropped ( cx) ) . await ;
290
+ assert ! ( trigger. is_dropped( ) ) ;
291
+ }
292
+
245
293
#[ tokio:: test( flavor = "multi_thread" ) ]
246
294
async fn tokio_select ( ) {
247
295
use std:: time:: Duration ;
0 commit comments