@ -1,11 +1,10 @@
#![ cfg(feature = " unstable " ) ]
#![ allow(deprecated) ]
use std ::sync ::atomic ::{ AtomicUsize , Ordering } ;
use std ::sync ::Arc ;
use std ::time ::Duration ;
use async_std ::sync:: channel ;
use async_std ::channel::bounded as channel ;
use async_std ::task ;
use rand ::{ Rng , SeedableRng } ;
@ -27,10 +26,10 @@ fn smoke() {
task ::block_on ( async {
let ( s , r ) = channel ( 1 ) ;
s . send ( 7 ) . await ;
s . send ( 7 ) . await .unwrap ( ) ;
assert_eq! ( r . recv ( ) . await . unwrap ( ) , 7 ) ;
s . send ( 8 ) . await ;
s . send ( 8 ) . await .unwrap ( ) ;
assert_eq! ( r . recv ( ) . await . unwrap ( ) , 8 ) ;
drop ( s ) ;
@ -40,7 +39,7 @@ fn smoke() {
task ::block_on ( async {
let ( s , r ) = channel ( 10 ) ;
drop ( r ) ;
s . send ( 1 ) . await ;
assert! ( s . send ( 1 ) . await . is_err ( ) ) ;
} ) ;
}
@ -49,8 +48,8 @@ fn smoke() {
fn capacity ( ) {
for i in 1 .. 10 {
let ( s , r ) = channel ::< ( ) > ( i ) ;
assert_eq! ( s . capacity ( ) , i ) ;
assert_eq! ( r . capacity ( ) , i ) ;
assert_eq! ( s . capacity ( ) .unwrap ( ) , i ) ;
assert_eq! ( r . capacity ( ) .unwrap ( ) , i ) ;
}
}
@ -68,7 +67,7 @@ fn len_empty_full() {
assert_eq! ( r . is_empty ( ) , true ) ;
assert_eq! ( r . is_full ( ) , false ) ;
s . send ( ( ) ) . await ;
s . send ( ( ) ) . await .unwrap ( ) ;
assert_eq! ( s . len ( ) , 1 ) ;
assert_eq! ( s . is_empty ( ) , false ) ;
@ -77,7 +76,7 @@ fn len_empty_full() {
assert_eq! ( r . is_empty ( ) , false ) ;
assert_eq! ( r . is_full ( ) , false ) ;
s . send ( ( ) ) . await ;
s . send ( ( ) ) . await .unwrap ( ) ;
assert_eq! ( s . len ( ) , 2 ) ;
assert_eq! ( s . is_empty ( ) , false ) ;
@ -113,9 +112,9 @@ fn recv() {
} ) ;
task ::sleep ( ms ( 1500 ) ) . await ;
s . send ( 7 ) . await ;
s . send ( 8 ) . await ;
s . send ( 9 ) . await ;
s . send ( 7 ) . await .unwrap ( ) ;
s . send ( 8 ) . await .unwrap ( ) ;
s . send ( 9 ) . await .unwrap ( ) ;
} )
}
@ -126,13 +125,13 @@ fn send() {
let ( s , r ) = channel ( 1 ) ;
spawn ( async move {
s . send ( 7 ) . await ;
s . send ( 7 ) . await .unwrap ( ) ;
task ::sleep ( ms ( 1000 ) ) . await ;
s . send ( 8 ) . await ;
s . send ( 8 ) . await .unwrap ( ) ;
task ::sleep ( ms ( 1000 ) ) . await ;
s . send ( 9 ) . await ;
s . send ( 9 ) . await .unwrap ( ) ;
task ::sleep ( ms ( 1000 ) ) . await ;
s . send ( 10 ) . await ;
s . send ( 10 ) . await .unwrap ( ) ;
} ) ;
task ::sleep ( ms ( 1500 ) ) . await ;
@ -148,9 +147,9 @@ fn recv_after_disconnect() {
task ::block_on ( async {
let ( s , r ) = channel ( 100 ) ;
s . send ( 1 ) . await ;
s . send ( 2 ) . await ;
s . send ( 3 ) . await ;
s . send ( 1 ) . await .unwrap ( ) ;
s . send ( 2 ) . await .unwrap ( ) ;
s . send ( 3 ) . await .unwrap ( ) ;
drop ( s ) ;
@ -175,7 +174,7 @@ fn len() {
for _ in 0 .. CAP / 10 {
for i in 0 .. 50 {
s . send ( i ) . await ;
s . send ( i ) . await .unwrap ( ) ;
assert_eq! ( s . len ( ) , i + 1 ) ;
}
@ -189,7 +188,7 @@ fn len() {
assert_eq! ( r . len ( ) , 0 ) ;
for i in 0 .. CAP {
s . send ( i ) . await ;
s . send ( i ) . await .unwrap ( ) ;
assert_eq! ( s . len ( ) , i + 1 ) ;
}
@ -212,7 +211,7 @@ fn len() {
} ) ;
for i in 0 .. COUNT {
s . send ( i ) . await ;
s . send ( i ) . await .unwrap ( ) ;
let len = s . len ( ) ;
assert! ( len < = CAP ) ;
}
@ -257,7 +256,7 @@ fn spsc() {
} ) ;
for i in 0 .. COUNT {
s . send ( i ) . await ;
s . send ( i ) . await .unwrap ( ) ;
}
drop ( s ) ;
@ -293,7 +292,7 @@ fn mpmc() {
let s = s . clone ( ) ;
tasks . push ( spawn ( async move {
for i in 0 .. COUNT {
s . send ( i ) . await ;
s . send ( i ) . await .unwrap ( ) ;
}
} ) ) ;
}
@ -318,7 +317,7 @@ fn oneshot() {
let ( s , r ) = channel ( 1 ) ;
let c1 = spawn ( async move { r . recv ( ) . await . unwrap ( ) } ) ;
let c2 = spawn ( async move { s . send ( 0 ) . await } ) ;
let c2 = spawn ( async move { s . send ( 0 ) . await . unwrap ( ) } ) ;
c1 . await ;
c2 . await ;
@ -361,13 +360,13 @@ fn drops() {
} ) ;
for _ in 0 .. steps {
s . send ( DropCounter ) . await ;
s . send ( DropCounter ) . await .unwrap ( ) ;
}
child . await ;
for _ in 0 .. additional {
s . send ( DropCounter ) . await ;
s . send ( DropCounter ) . await .unwrap ( ) ;
}
assert_eq! ( DROPS . load ( Ordering ::SeqCst ) , steps ) ;