feat: new channels

- add new top level `channels` module (stable) based on `async-channel`
- deprecate `sync::channel`
pull/915/head
dignifiedquire 5 years ago
parent 73035006dc
commit 8c0e319e94

@ -52,6 +52,7 @@ std = [
"wasm-bindgen-futures",
"futures-channel",
"async-mutex",
"async-channel",
]
alloc = [
"futures-core/alloc",
@ -74,10 +75,12 @@ once_cell = { version = "1.3.1", optional = true }
pin-project-lite = { version = "0.2.0", optional = true }
pin-utils = { version = "0.1.0-alpha.4", optional = true }
slab = { version = "0.4.2", optional = true }
async-channel = { version = "1.5.1", optional = true }
# Devdepencency, but they are not allowed to be optional :/
surf = { version = "2.0.0", optional = true }
[target.'cfg(not(target_os = "unknown"))'.dependencies]
async-global-executor = { version = "1.4.0", optional = true, features = ["async-io"] }
async-io = { version = "1.0.1", optional = true }

@ -0,0 +1,6 @@
//! Channels
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[doc(inline)]
pub use async_channel::*;

@ -106,15 +106,14 @@
//! [`io`], [`fs`], and [`net`] modules.
//!
//! The [`task`] module contains `async-std`'s task abstractions. [`sync`]
//! contains further primitive shared memory types, including [`channel`],
//! which contains the channel types for message passing.
//! contains further primitive shared memory types. [`channel`] contains the channel types for message passing.
//!
//! [files]: fs/struct.File.html
//! [TCP]: net/struct.TcpStream.html
//! [UDP]: net/struct.UdpSocket.html
//! [`io`]: fs/struct.File.html
//! [`sync`]: sync/index.html
//! [`channel`]: sync/fn.channel.html
//! [`channel`]: channel/index.html
//!
//! ## Timeouts, intervals, and delays
//!
@ -300,6 +299,7 @@ cfg_std! {
pub mod os;
pub mod prelude;
pub mod sync;
pub mod channel;
}
cfg_default! {

@ -60,6 +60,7 @@ use crate::sync::WakerSet;
/// ```
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[deprecated = "new channel api at async_std::channel"]
pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
let channel = Arc::new(Channel::with_capacity(cap));
let s = Sender {
@ -102,6 +103,7 @@ pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
/// ```
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[deprecated = "new channel api at async_std::channel"]
pub struct Sender<T> {
/// The inner channel.
channel: Arc<Channel<T>>,
@ -363,6 +365,7 @@ impl<T> fmt::Debug for Sender<T> {
/// ```
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[deprecated = "new channel api at async_std::channel"]
pub struct Receiver<T> {
/// The inner channel.
channel: Arc<Channel<T>>,
@ -993,6 +996,7 @@ impl<T> Drop for Channel<T> {
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[derive(PartialEq, Eq)]
#[deprecated = "new channel api at async_std::channel"]
pub enum TrySendError<T> {
/// The channel is full but not disconnected.
Full(T),
@ -1025,6 +1029,7 @@ impl<T> Display for TrySendError<T> {
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[derive(Debug, PartialEq, Eq)]
#[deprecated = "new channel api at async_std::channel"]
pub enum TryRecvError {
/// The channel is empty but not disconnected.
Empty,
@ -1048,6 +1053,7 @@ impl Display for TryRecvError {
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[derive(Debug, PartialEq, Eq)]
#[deprecated = "new channel api at async_std::channel"]
pub struct RecvError;
impl Error for RecvError {}

Loading…
Cancel
Save