mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
remove deprecated sync::channel
This commit is contained in:
parent
684ab185fe
commit
8c5238743b
5 changed files with 30 additions and 1122 deletions
|
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
|
||||||
|
|
||||||
- Add `tokio1` feature ([#924](https://github.com/async-rs/async-std/pull/924))
|
- Add `tokio1` feature ([#924](https://github.com/async-rs/async-std/pull/924))
|
||||||
|
|
||||||
|
## Removed
|
||||||
|
|
||||||
|
- Removed deprecated `sync::channel`
|
||||||
|
|
||||||
# [1.8.0] - 2020-12-04
|
# [1.8.0] - 2020-12-04
|
||||||
|
|
||||||
This patch introduces `async_std::channel`, a new submodule for our async channels implementation. `channels` have been one of async-std's most requested features, and have existed as "unstable" for the past year. We've been cautious about stabilizing channels, and this caution turned out to be warranted: we realized our channels could hang indefinitely under certain circumstances, and people ended up expressing a need for unbounded channels.
|
This patch introduces `async_std::channel`, a new submodule for our async channels implementation. `channels` have been one of async-std's most requested features, and have existed as "unstable" for the past year. We've been cautious about stabilizing channels, and this caution turned out to be warranted: we realized our channels could hang indefinitely under certain circumstances, and people ended up expressing a need for unbounded channels.
|
||||||
|
|
1082
src/sync/channel.rs
1082
src/sync/channel.rs
File diff suppressed because it is too large
Load diff
|
@ -184,13 +184,10 @@ pub use async_lock::{RwLock, RwLockReadGuard, RwLockUpgradableReadGuard, RwLockW
|
||||||
|
|
||||||
cfg_unstable! {
|
cfg_unstable! {
|
||||||
pub use async_lock::{Barrier, BarrierWaitResult};
|
pub use async_lock::{Barrier, BarrierWaitResult};
|
||||||
#[allow(deprecated)]
|
|
||||||
pub use channel::{channel, Sender, Receiver, RecvError, TryRecvError, TrySendError};
|
|
||||||
pub use condvar::Condvar;
|
pub use condvar::Condvar;
|
||||||
pub(crate) use waker_set::WakerSet;
|
pub(crate) use waker_set::WakerSet;
|
||||||
|
|
||||||
mod condvar;
|
mod condvar;
|
||||||
mod channel;
|
|
||||||
|
|
||||||
pub(crate) mod waker_set;
|
pub(crate) mod waker_set;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,16 +70,6 @@ impl WakerSet {
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the waker of an operation.
|
|
||||||
#[cold]
|
|
||||||
pub fn remove(&self, key: usize) {
|
|
||||||
let mut inner = self.lock();
|
|
||||||
|
|
||||||
if inner.entries.remove(key).is_some() {
|
|
||||||
inner.notifiable -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If the waker for this key is still waiting for a notification, then update
|
/// If the waker for this key is still waiting for a notification, then update
|
||||||
/// the waker for the entry, and return false. If the waker has been notified,
|
/// the waker for the entry, and return false. If the waker has been notified,
|
||||||
/// treat the entry as completed and return true.
|
/// treat the entry as completed and return true.
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#![cfg(feature = "unstable")]
|
#![cfg(feature = "unstable")]
|
||||||
#![allow(deprecated)]
|
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use async_std::sync::channel;
|
use async_std::channel::bounded as channel;
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
|
|
||||||
|
@ -27,10 +26,10 @@ fn smoke() {
|
||||||
task::block_on(async {
|
task::block_on(async {
|
||||||
let (s, r) = channel(1);
|
let (s, r) = channel(1);
|
||||||
|
|
||||||
s.send(7).await;
|
s.send(7).await.unwrap();
|
||||||
assert_eq!(r.recv().await.unwrap(), 7);
|
assert_eq!(r.recv().await.unwrap(), 7);
|
||||||
|
|
||||||
s.send(8).await;
|
s.send(8).await.unwrap();
|
||||||
assert_eq!(r.recv().await.unwrap(), 8);
|
assert_eq!(r.recv().await.unwrap(), 8);
|
||||||
|
|
||||||
drop(s);
|
drop(s);
|
||||||
|
@ -40,7 +39,7 @@ fn smoke() {
|
||||||
task::block_on(async {
|
task::block_on(async {
|
||||||
let (s, r) = channel(10);
|
let (s, r) = channel(10);
|
||||||
drop(r);
|
drop(r);
|
||||||
s.send(1).await;
|
assert!(s.send(1).await.is_err());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +48,8 @@ fn smoke() {
|
||||||
fn capacity() {
|
fn capacity() {
|
||||||
for i in 1..10 {
|
for i in 1..10 {
|
||||||
let (s, r) = channel::<()>(i);
|
let (s, r) = channel::<()>(i);
|
||||||
assert_eq!(s.capacity(), i);
|
assert_eq!(s.capacity().unwrap(), i);
|
||||||
assert_eq!(r.capacity(), 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_empty(), true);
|
||||||
assert_eq!(r.is_full(), false);
|
assert_eq!(r.is_full(), false);
|
||||||
|
|
||||||
s.send(()).await;
|
s.send(()).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(s.len(), 1);
|
assert_eq!(s.len(), 1);
|
||||||
assert_eq!(s.is_empty(), false);
|
assert_eq!(s.is_empty(), false);
|
||||||
|
@ -77,7 +76,7 @@ fn len_empty_full() {
|
||||||
assert_eq!(r.is_empty(), false);
|
assert_eq!(r.is_empty(), false);
|
||||||
assert_eq!(r.is_full(), false);
|
assert_eq!(r.is_full(), false);
|
||||||
|
|
||||||
s.send(()).await;
|
s.send(()).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(s.len(), 2);
|
assert_eq!(s.len(), 2);
|
||||||
assert_eq!(s.is_empty(), false);
|
assert_eq!(s.is_empty(), false);
|
||||||
|
@ -113,9 +112,9 @@ fn recv() {
|
||||||
});
|
});
|
||||||
|
|
||||||
task::sleep(ms(1500)).await;
|
task::sleep(ms(1500)).await;
|
||||||
s.send(7).await;
|
s.send(7).await.unwrap();
|
||||||
s.send(8).await;
|
s.send(8).await.unwrap();
|
||||||
s.send(9).await;
|
s.send(9).await.unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,13 +125,13 @@ fn send() {
|
||||||
let (s, r) = channel(1);
|
let (s, r) = channel(1);
|
||||||
|
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
s.send(7).await;
|
s.send(7).await.unwrap();
|
||||||
task::sleep(ms(1000)).await;
|
task::sleep(ms(1000)).await;
|
||||||
s.send(8).await;
|
s.send(8).await.unwrap();
|
||||||
task::sleep(ms(1000)).await;
|
task::sleep(ms(1000)).await;
|
||||||
s.send(9).await;
|
s.send(9).await.unwrap();
|
||||||
task::sleep(ms(1000)).await;
|
task::sleep(ms(1000)).await;
|
||||||
s.send(10).await;
|
s.send(10).await.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
task::sleep(ms(1500)).await;
|
task::sleep(ms(1500)).await;
|
||||||
|
@ -148,9 +147,9 @@ fn recv_after_disconnect() {
|
||||||
task::block_on(async {
|
task::block_on(async {
|
||||||
let (s, r) = channel(100);
|
let (s, r) = channel(100);
|
||||||
|
|
||||||
s.send(1).await;
|
s.send(1).await.unwrap();
|
||||||
s.send(2).await;
|
s.send(2).await.unwrap();
|
||||||
s.send(3).await;
|
s.send(3).await.unwrap();
|
||||||
|
|
||||||
drop(s);
|
drop(s);
|
||||||
|
|
||||||
|
@ -175,7 +174,7 @@ fn len() {
|
||||||
|
|
||||||
for _ in 0..CAP / 10 {
|
for _ in 0..CAP / 10 {
|
||||||
for i in 0..50 {
|
for i in 0..50 {
|
||||||
s.send(i).await;
|
s.send(i).await.unwrap();
|
||||||
assert_eq!(s.len(), i + 1);
|
assert_eq!(s.len(), i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +188,7 @@ fn len() {
|
||||||
assert_eq!(r.len(), 0);
|
assert_eq!(r.len(), 0);
|
||||||
|
|
||||||
for i in 0..CAP {
|
for i in 0..CAP {
|
||||||
s.send(i).await;
|
s.send(i).await.unwrap();
|
||||||
assert_eq!(s.len(), i + 1);
|
assert_eq!(s.len(), i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +211,7 @@ fn len() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for i in 0..COUNT {
|
for i in 0..COUNT {
|
||||||
s.send(i).await;
|
s.send(i).await.unwrap();
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
assert!(len <= CAP);
|
assert!(len <= CAP);
|
||||||
}
|
}
|
||||||
|
@ -257,7 +256,7 @@ fn spsc() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for i in 0..COUNT {
|
for i in 0..COUNT {
|
||||||
s.send(i).await;
|
s.send(i).await.unwrap();
|
||||||
}
|
}
|
||||||
drop(s);
|
drop(s);
|
||||||
|
|
||||||
|
@ -293,7 +292,7 @@ fn mpmc() {
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
tasks.push(spawn(async move {
|
tasks.push(spawn(async move {
|
||||||
for i in 0..COUNT {
|
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 (s, r) = channel(1);
|
||||||
|
|
||||||
let c1 = spawn(async move { r.recv().await.unwrap() });
|
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;
|
c1.await;
|
||||||
c2.await;
|
c2.await;
|
||||||
|
@ -361,13 +360,13 @@ fn drops() {
|
||||||
});
|
});
|
||||||
|
|
||||||
for _ in 0..steps {
|
for _ in 0..steps {
|
||||||
s.send(DropCounter).await;
|
s.send(DropCounter).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
child.await;
|
child.await;
|
||||||
|
|
||||||
for _ in 0..additional {
|
for _ in 0..additional {
|
||||||
s.send(DropCounter).await;
|
s.send(DropCounter).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(DROPS.load(Ordering::SeqCst), steps);
|
assert_eq!(DROPS.load(Ordering::SeqCst), steps);
|
||||||
|
|
Loading…
Reference in a new issue