Skip to content

Commit 8c0e319

Browse files
feat: new channels
- add new top level `channels` module (stable) based on `async-channel` - deprecate `sync::channel`
1 parent 7303500 commit 8c0e319

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std = [
5252
"wasm-bindgen-futures",
5353
"futures-channel",
5454
"async-mutex",
55+
"async-channel",
5556
]
5657
alloc = [
5758
"futures-core/alloc",
@@ -74,10 +75,12 @@ once_cell = { version = "1.3.1", optional = true }
7475
pin-project-lite = { version = "0.2.0", optional = true }
7576
pin-utils = { version = "0.1.0-alpha.4", optional = true }
7677
slab = { version = "0.4.2", optional = true }
78+
async-channel = { version = "1.5.1", optional = true }
7779

7880
# Devdepencency, but they are not allowed to be optional :/
7981
surf = { version = "2.0.0", optional = true }
8082

83+
8184
[target.'cfg(not(target_os = "unknown"))'.dependencies]
8285
async-global-executor = { version = "1.4.0", optional = true, features = ["async-io"] }
8386
async-io = { version = "1.0.1", optional = true }

src/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Channels
2+
3+
#[cfg(feature = "unstable")]
4+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
5+
#[doc(inline)]
6+
pub use async_channel::*;

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@
106106
//! [`io`], [`fs`], and [`net`] modules.
107107
//!
108108
//! The [`task`] module contains `async-std`'s task abstractions. [`sync`]
109-
//! contains further primitive shared memory types, including [`channel`],
110-
//! which contains the channel types for message passing.
109+
//! contains further primitive shared memory types. [`channel`] contains the channel types for message passing.
111110
//!
112111
//! [files]: fs/struct.File.html
113112
//! [TCP]: net/struct.TcpStream.html
114113
//! [UDP]: net/struct.UdpSocket.html
115114
//! [`io`]: fs/struct.File.html
116115
//! [`sync`]: sync/index.html
117-
//! [`channel`]: sync/fn.channel.html
116+
//! [`channel`]: channel/index.html
118117
//!
119118
//! ## Timeouts, intervals, and delays
120119
//!
@@ -300,6 +299,7 @@ cfg_std! {
300299
pub mod os;
301300
pub mod prelude;
302301
pub mod sync;
302+
pub mod channel;
303303
}
304304

305305
cfg_default! {

src/sync/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use crate::sync::WakerSet;
6060
/// ```
6161
#[cfg(feature = "unstable")]
6262
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
63+
#[deprecated = "new channel api at async_std::channel"]
6364
pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
6465
let channel = Arc::new(Channel::with_capacity(cap));
6566
let s = Sender {
@@ -102,6 +103,7 @@ pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
102103
/// ```
103104
#[cfg(feature = "unstable")]
104105
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
106+
#[deprecated = "new channel api at async_std::channel"]
105107
pub struct Sender<T> {
106108
/// The inner channel.
107109
channel: Arc<Channel<T>>,
@@ -363,6 +365,7 @@ impl<T> fmt::Debug for Sender<T> {
363365
/// ```
364366
#[cfg(feature = "unstable")]
365367
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
368+
#[deprecated = "new channel api at async_std::channel"]
366369
pub struct Receiver<T> {
367370
/// The inner channel.
368371
channel: Arc<Channel<T>>,
@@ -993,6 +996,7 @@ impl<T> Drop for Channel<T> {
993996
#[cfg(feature = "unstable")]
994997
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
995998
#[derive(PartialEq, Eq)]
999+
#[deprecated = "new channel api at async_std::channel"]
9961000
pub enum TrySendError<T> {
9971001
/// The channel is full but not disconnected.
9981002
Full(T),
@@ -1025,6 +1029,7 @@ impl<T> Display for TrySendError<T> {
10251029
#[cfg(feature = "unstable")]
10261030
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
10271031
#[derive(Debug, PartialEq, Eq)]
1032+
#[deprecated = "new channel api at async_std::channel"]
10281033
pub enum TryRecvError {
10291034
/// The channel is empty but not disconnected.
10301035
Empty,
@@ -1048,6 +1053,7 @@ impl Display for TryRecvError {
10481053
#[cfg(feature = "unstable")]
10491054
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
10501055
#[derive(Debug, PartialEq, Eq)]
1056+
#[deprecated = "new channel api at async_std::channel"]
10511057
pub struct RecvError;
10521058

10531059
impl Error for RecvError {}

0 commit comments

Comments
 (0)