1
- use async_std:: prelude:: * ;
2
1
use async_std:: future:: Future ;
3
- use pin_project_lite:: pin_project;
4
- use async_std:: task:: { self , Context , Poll } ;
2
+ use async_std:: prelude:: * ;
5
3
use async_std:: sync:: { self , Receiver , Sender } ;
4
+ use async_std:: task:: { self , Context , Poll } ;
5
+ use pin_project_lite:: pin_project;
6
6
7
7
use std:: pin:: Pin ;
8
8
use std:: sync:: atomic:: { AtomicBool , AtomicU64 , Ordering } ;
@@ -59,13 +59,14 @@ impl Any {
59
59
task:: spawn ( async move {
60
60
// Execute the closure.
61
61
let res = f ( item) . await ;
62
+ value. fetch_or ( res, Ordering :: SeqCst ) ;
62
63
63
64
// Wake up the receiver if we know we're done.
64
65
ref_count. fetch_sub ( 1 , Ordering :: SeqCst ) ;
65
- if res {
66
- value . fetch_or ( true , Ordering :: SeqCst ) ;
67
- sender . send ( ( ) ) . await ;
68
- } else if exhausted . load ( Ordering :: SeqCst ) && ref_count . load ( Ordering :: SeqCst ) == 0 {
66
+ if value . load ( Ordering :: SeqCst )
67
+ || ( exhausted . load ( Ordering :: SeqCst )
68
+ && ref_count . load ( Ordering :: SeqCst ) == 0 )
69
+ {
69
70
sender. send ( ( ) ) . await ;
70
71
}
71
72
} ) ;
@@ -91,13 +92,10 @@ impl Future for Any {
91
92
92
93
#[ async_std:: test]
93
94
async fn smoke ( ) {
94
- let s = async_std:: stream:: repeat ( 5usize ) ;
95
+ let s = async_std:: stream:: from_iter ( vec ! [ 6 , 9 , 0 , 7 , 10 ] ) ;
95
96
let result = crate :: from_stream ( s)
96
- . take ( 3 )
97
- . any ( |n| async move {
98
- n * 2 < 9
99
- } )
97
+ . any ( |n| async move { n * 2 < 9 } )
100
98
. await ;
101
-
102
- assert_eq ! ( result, false ) ;
99
+
100
+ assert ! ( result) ;
103
101
}
0 commit comments