Skip to content

Commit 6ae69c9

Browse files
authored
Merge pull request #915 from async-rs/feat-new-channels
feat: new channels
2 parents 7303500 + da236ae commit 6ae69c9

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

Cargo.toml

+3
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

+6
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

+3-3
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

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(deprecated)]
2+
13
use std::cell::UnsafeCell;
24
use std::error::Error;
35
use std::fmt::{self, Debug, Display};
@@ -32,6 +34,7 @@ use crate::sync::WakerSet;
3234
/// # Examples
3335
///
3436
/// ```
37+
/// #![allow(deprecated)]
3538
/// # fn main() -> Result<(), async_std::sync::RecvError> {
3639
/// # async_std::task::block_on(async {
3740
/// #
@@ -60,6 +63,7 @@ use crate::sync::WakerSet;
6063
/// ```
6164
#[cfg(feature = "unstable")]
6265
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
66+
#[deprecated = "new channel api at async_std::channel"]
6367
pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
6468
let channel = Arc::new(Channel::with_capacity(cap));
6569
let s = Sender {
@@ -82,6 +86,7 @@ pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
8286
/// # Examples
8387
///
8488
/// ```
89+
/// #![allow(deprecated)]
8590
/// # async_std::task::block_on(async {
8691
/// #
8792
/// use async_std::sync::channel;
@@ -102,6 +107,7 @@ pub fn channel<T>(cap: usize) -> (Sender<T>, Receiver<T>) {
102107
/// ```
103108
#[cfg(feature = "unstable")]
104109
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
110+
#[deprecated = "new channel api at async_std::channel"]
105111
pub struct Sender<T> {
106112
/// The inner channel.
107113
channel: Arc<Channel<T>>,
@@ -115,6 +121,7 @@ impl<T> Sender<T> {
115121
/// # Examples
116122
///
117123
/// ```
124+
/// #![allow(deprecated)]
118125
/// # fn main() -> Result<(), async_std::sync::RecvError> {
119126
/// # async_std::task::block_on(async {
120127
/// #
@@ -204,6 +211,7 @@ impl<T> Sender<T> {
204211
/// # Examples
205212
///
206213
/// ```
214+
/// #![allow(deprecated)]
207215
/// # async_std::task::block_on(async {
208216
/// #
209217
/// use async_std::sync::channel;
@@ -223,6 +231,7 @@ impl<T> Sender<T> {
223231
/// # Examples
224232
///
225233
/// ```
234+
/// #![allow(deprecated)]
226235
/// use async_std::sync::channel;
227236
///
228237
/// let (s, _) = channel::<i32>(5);
@@ -237,6 +246,7 @@ impl<T> Sender<T> {
237246
/// # Examples
238247
///
239248
/// ```
249+
/// #![allow(deprecated)]
240250
/// # async_std::task::block_on(async {
241251
/// #
242252
/// use async_std::sync::channel;
@@ -258,6 +268,7 @@ impl<T> Sender<T> {
258268
/// # Examples
259269
///
260270
/// ```
271+
/// #![allow(deprecated)]
261272
/// # async_std::task::block_on(async {
262273
/// #
263274
/// use async_std::sync::channel;
@@ -279,6 +290,7 @@ impl<T> Sender<T> {
279290
/// # Examples
280291
///
281292
/// ```
293+
/// #![allow(deprecated)]
282294
/// # async_std::task::block_on(async {
283295
/// #
284296
/// use async_std::sync::channel;
@@ -339,6 +351,7 @@ impl<T> fmt::Debug for Sender<T> {
339351
/// # Examples
340352
///
341353
/// ```
354+
/// #![allow(deprecated)]
342355
/// # fn main() -> Result<(), async_std::sync::RecvError> {
343356
/// # async_std::task::block_on(async {
344357
/// #
@@ -363,6 +376,7 @@ impl<T> fmt::Debug for Sender<T> {
363376
/// ```
364377
#[cfg(feature = "unstable")]
365378
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
379+
#[deprecated = "new channel api at async_std::channel"]
366380
pub struct Receiver<T> {
367381
/// The inner channel.
368382
channel: Arc<Channel<T>>,
@@ -381,6 +395,7 @@ impl<T> Receiver<T> {
381395
/// # Examples
382396
///
383397
/// ```
398+
/// #![allow(deprecated)]
384399
/// # fn main() -> Result<(), async_std::sync::RecvError> {
385400
/// # async_std::task::block_on(async {
386401
/// #
@@ -444,6 +459,7 @@ impl<T> Receiver<T> {
444459
/// # Examples
445460
///
446461
/// ```
462+
/// #![allow(deprecated)]
447463
/// # async_std::task::block_on(async {
448464
/// #
449465
/// use async_std::sync::channel;
@@ -466,6 +482,7 @@ impl<T> Receiver<T> {
466482
/// # Examples
467483
///
468484
/// ```
485+
/// #![allow(deprecated)]
469486
/// use async_std::sync::channel;
470487
///
471488
/// let (_, r) = channel::<i32>(5);
@@ -480,6 +497,7 @@ impl<T> Receiver<T> {
480497
/// # Examples
481498
///
482499
/// ```
500+
/// #![allow(deprecated)]
483501
/// # async_std::task::block_on(async {
484502
/// #
485503
/// use async_std::sync::channel;
@@ -501,6 +519,7 @@ impl<T> Receiver<T> {
501519
/// # Examples
502520
///
503521
/// ```
522+
/// #![allow(deprecated)]
504523
/// # async_std::task::block_on(async {
505524
/// #
506525
/// use async_std::sync::channel;
@@ -522,6 +541,7 @@ impl<T> Receiver<T> {
522541
/// # Examples
523542
///
524543
/// ```
544+
/// #![allow(deprecated)]
525545
/// # async_std::task::block_on(async {
526546
/// #
527547
/// use async_std::sync::channel;
@@ -993,6 +1013,7 @@ impl<T> Drop for Channel<T> {
9931013
#[cfg(feature = "unstable")]
9941014
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
9951015
#[derive(PartialEq, Eq)]
1016+
#[deprecated = "new channel api at async_std::channel"]
9961017
pub enum TrySendError<T> {
9971018
/// The channel is full but not disconnected.
9981019
Full(T),
@@ -1025,6 +1046,7 @@ impl<T> Display for TrySendError<T> {
10251046
#[cfg(feature = "unstable")]
10261047
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
10271048
#[derive(Debug, PartialEq, Eq)]
1049+
#[deprecated = "new channel api at async_std::channel"]
10281050
pub enum TryRecvError {
10291051
/// The channel is empty but not disconnected.
10301052
Empty,
@@ -1048,6 +1070,7 @@ impl Display for TryRecvError {
10481070
#[cfg(feature = "unstable")]
10491071
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
10501072
#[derive(Debug, PartialEq, Eq)]
1073+
#[deprecated = "new channel api at async_std::channel"]
10511074
pub struct RecvError;
10521075

10531076
impl Error for RecvError {}

src/sync/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ mod rwlock;
185185

186186
cfg_unstable! {
187187
pub use barrier::{Barrier, BarrierWaitResult};
188+
#[allow(deprecated)]
188189
pub use channel::{channel, Sender, Receiver, RecvError, TryRecvError, TrySendError};
189190
pub use condvar::Condvar;
190191

tests/channel.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg(feature = "unstable")]
2+
#![allow(deprecated)]
23

34
use std::sync::atomic::{AtomicUsize, Ordering};
45
use std::sync::Arc;

tests/stream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::task::{Context, Poll};
55

66
use pin_project_lite::pin_project;
77

8+
use async_std::channel::bounded as channel;
89
use async_std::prelude::*;
910
use async_std::stream;
10-
use async_std::sync::channel;
1111
use async_std::task;
1212

1313
#[cfg(target_arch = "wasm32")]
@@ -36,7 +36,7 @@ fn merging_delayed_streams_work() {
3636

3737
task::block_on(async move {
3838
task::sleep(std::time::Duration::from_millis(500)).await;
39-
sender.send(92).await;
39+
sender.send(92).await.unwrap();
4040
drop(sender);
4141
let xs = t.await;
4242
assert_eq!(xs, vec![92])
@@ -55,7 +55,7 @@ fn merging_delayed_streams_work() {
5555

5656
task::block_on(async move {
5757
task::sleep(std::time::Duration::from_millis(500)).await;
58-
sender.send(92).await;
58+
sender.send(92).await.unwrap();
5959
drop(sender);
6060
let xs = t.await;
6161
assert_eq!(xs, vec![92])

0 commit comments

Comments
 (0)