Skip to content

Commit 1dedf93

Browse files
akhillesjbr
authored andcommitted
async_std::sync::channel -> async_channel
1 parent c124be5 commit 1dedf93

File tree

6 files changed

+26
-35
lines changed

6 files changed

+26
-35
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cookie-secure = ["cookie/secure"]
2828
# features: async_std
2929
async-std = { version = "1.6.0", features = ["unstable"] }
3030
futures-lite = "1.7.0"
31+
async-channel = "1.4.2"
3132

3233
# features: hyperium/http
3334
http = { version = "0.2.0", optional = true }

src/request.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use async_std::sync;
21
use futures_lite::*;
32

43
use std::convert::{Into, TryInto};
@@ -38,8 +37,8 @@ pin_project_lite::pin_project! {
3837
local_addr: Option<String>,
3938
peer_addr: Option<String>,
4039
ext: Extensions,
41-
trailers_sender: Option<sync::Sender<Trailers>>,
42-
trailers_receiver: Option<sync::Receiver<Trailers>>,
40+
trailers_sender: Option<async_channel::Sender<Trailers>>,
41+
trailers_receiver: Option<async_channel::Receiver<Trailers>>,
4342
has_trailers: bool,
4443
}
4544
}
@@ -52,7 +51,7 @@ impl Request {
5251
U::Error: std::fmt::Debug,
5352
{
5453
let url = url.try_into().expect("Could not convert into a valid url");
55-
let (trailers_sender, trailers_receiver) = sync::channel(1);
54+
let (trailers_sender, trailers_receiver) = async_channel::bounded(1);
5655
Self {
5756
method,
5857
url,

src/response.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use async_std::sync;
21
use futures_lite::*;
32

43
use std::convert::{Into, TryInto};
@@ -43,8 +42,8 @@ pin_project_lite::pin_project! {
4342
headers: Headers,
4443
version: Option<Version>,
4544
has_trailers: bool,
46-
trailers_sender: Option<sync::Sender<Trailers>>,
47-
trailers_receiver: Option<sync::Receiver<Trailers>>,
45+
trailers_sender: Option<async_channel::Sender<Trailers>>,
46+
trailers_receiver: Option<async_channel::Receiver<Trailers>>,
4847
#[pin]
4948
body: Body,
5049
ext: Extensions,
@@ -74,11 +73,11 @@ pin_project_lite::pin_project! {
7473
status: StatusCode,
7574
headers: Headers,
7675
version: Option<Version>,
77-
trailers_sender: Option<sync::Sender<Trailers>>,
78-
trailers_receiver: Option<sync::Receiver<Trailers>>,
76+
trailers_sender: Option<async_channel::Sender<Trailers>>,
77+
trailers_receiver: Option<async_channel::Receiver<Trailers>>,
7978
has_trailers: bool,
80-
upgrade_sender: Option<sync::Sender<upgrade::Connection>>,
81-
upgrade_receiver: Option<sync::Receiver<upgrade::Connection>>,
79+
upgrade_sender: Option<async_channel::Sender<upgrade::Connection>>,
80+
upgrade_receiver: Option<async_channel::Receiver<upgrade::Connection>>,
8281
has_upgrade: bool,
8382
#[pin]
8483
body: Body,
@@ -99,7 +98,7 @@ impl Response {
9998
let status = status
10099
.try_into()
101100
.expect("Could not convert into a valid `StatusCode`");
102-
let (trailers_sender, trailers_receiver) = sync::channel(1);
101+
let (trailers_sender, trailers_receiver) = async_channel::bounded(1);
103102
Self {
104103
status,
105104
headers: Headers::new(),
@@ -124,8 +123,8 @@ impl Response {
124123
let status = status
125124
.try_into()
126125
.expect("Could not convert into a valid `StatusCode`");
127-
let (trailers_sender, trailers_receiver) = sync::channel(1);
128-
let (upgrade_sender, upgrade_receiver) = sync::channel(1);
126+
let (trailers_sender, trailers_receiver) = async_channel::bounded(1);
127+
let (upgrade_sender, upgrade_receiver) = async_channel::bounded(1);
129128
Self {
130129
status,
131130
headers: Headers::new(),

src/trailers.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
use crate::headers::{
5151
HeaderName, HeaderValues, Headers, Iter, IterMut, Names, ToHeaderValues, Values,
5252
};
53-
use async_std::sync;
5453
use futures_lite::*;
5554

5655
use std::convert::Into;
@@ -207,43 +206,43 @@ impl Index<&str> for Trailers {
207206

208207
/// The sending half of a channel to send trailers.
209208
///
210-
/// Unlike `async_std::sync::channel` the `send` method on this type can only be
209+
/// Unlike `async_channel::Sender` the `send` method on this type can only be
211210
/// called once, and cannot be cloned. That's because only a single instance of
212211
/// `Trailers` should be created.
213212
#[derive(Debug)]
214213
pub struct Sender {
215-
sender: sync::Sender<Trailers>,
214+
sender: async_channel::Sender<Trailers>,
216215
}
217216

218217
impl Sender {
219218
/// Create a new instance of `Sender`.
220219
#[doc(hidden)]
221-
pub fn new(sender: sync::Sender<Trailers>) -> Self {
220+
pub fn new(sender: async_channel::Sender<Trailers>) -> Self {
222221
Self { sender }
223222
}
224223

225224
/// Send a `Trailer`.
226225
///
227226
/// The channel will be consumed after having sent trailers.
228227
pub async fn send(self, trailers: Trailers) {
229-
self.sender.send(trailers).await
228+
let _ = self.sender.send(trailers).await;
230229
}
231230
}
232231

233232
/// The receiving half of a channel to send trailers.
234233
///
235-
/// Unlike `async_std::sync::channel` the `send` method on this type can only be
234+
/// Unlike `async_channel::Sender` the `send` method on this type can only be
236235
/// called once, and cannot be cloned. That's because only a single instance of
237236
/// `Trailers` should be created.
238237
#[must_use = "Futures do nothing unless polled or .awaited"]
239238
#[derive(Debug)]
240239
pub struct Receiver {
241-
receiver: sync::Receiver<Trailers>,
240+
receiver: async_channel::Receiver<Trailers>,
242241
}
243242

244243
impl Receiver {
245244
/// Create a new instance of `Receiver`.
246-
pub(crate) fn new(receiver: sync::Receiver<Trailers>) -> Self {
245+
pub(crate) fn new(receiver: async_channel::Receiver<Trailers>) -> Self {
247246
Self { receiver }
248247
}
249248
}

src/upgrade/receiver.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use async_std::sync;
21
use futures_lite::*;
32

43
use std::future::Future;
@@ -8,20 +7,16 @@ use std::task::{Context, Poll};
87
use crate::upgrade::Connection;
98

109
/// The receiving half of a channel to send an upgraded connection.
11-
///
12-
/// Unlike `async_std::sync::channel` the `send` method on this type can only be
13-
/// called once, and cannot be cloned. That's because only a single instance of
14-
/// `Connection` should be created.
1510
#[must_use = "Futures do nothing unless polled or .awaited"]
1611
#[derive(Debug)]
1712
pub struct Receiver {
18-
receiver: sync::Receiver<Connection>,
13+
receiver: async_channel::Receiver<Connection>,
1914
}
2015

2116
impl Receiver {
2217
/// Create a new instance of `Receiver`.
2318
#[allow(unused)]
24-
pub(crate) fn new(receiver: sync::Receiver<Connection>) -> Self {
19+
pub(crate) fn new(receiver: async_channel::Receiver<Connection>) -> Self {
2520
Self { receiver }
2621
}
2722
}

src/upgrade/sender.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
use async_std::sync;
2-
31
use crate::upgrade::Connection;
42

53
/// The sending half of a channel to send an upgraded connection.
64
///
7-
/// Unlike `async_std::sync::channel` the `send` method on this type can only be
5+
/// Unlike `async_channel::Sender` the `send` method on this type can only be
86
/// called once, and cannot be cloned. That's because only a single instance of
97
/// `Connection` should be created.
108
#[derive(Debug)]
119
pub struct Sender {
12-
sender: sync::Sender<Connection>,
10+
sender: async_channel::Sender<Connection>,
1311
}
1412

1513
impl Sender {
1614
/// Create a new instance of `Sender`.
1715
#[doc(hidden)]
18-
pub fn new(sender: sync::Sender<Connection>) -> Self {
16+
pub fn new(sender: async_channel::Sender<Connection>) -> Self {
1917
Self { sender }
2018
}
2119

2220
/// Send a `Trailer`.
2321
///
2422
/// The channel will be consumed after having sent trailers.
2523
pub async fn send(self, trailers: Connection) {
26-
self.sender.send(trailers).await
24+
let _ = self.sender.send(trailers).await;
2725
}
2826
}

0 commit comments

Comments
 (0)