File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -326,18 +326,20 @@ async fn test_task_detach() {
326326 let handle = TokioRuntime :: current ( ) ;
327327 let counter = Arc :: new ( AtomicUsize :: new ( 0 ) ) ;
328328 let c = counter. clone ( ) ;
329+ let ( tx, rx) = oneshot:: channel :: < ( ) > ( ) ;
329330
330331 let task = handle. spawn ( async move {
331332 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) . await ;
332333 c. fetch_add ( 1 , Ordering :: SeqCst ) ;
333- 42
334+ tx . send ( ( ) )
334335 } ) ;
335336
336337 // Detach the task so it continues running
337338 task. detach ( ) ;
338339
339340 // Wait for task to complete
340341 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 20 ) ) . await ;
342+ let _ = rx. await ;
341343
342344 // Task should have completed even though we detached it
343345 assert_eq ! ( counter. load( Ordering :: SeqCst ) , 1 ) ;
You can’t perform that action at this time.
0 commit comments