Skip to content

Commit 37ef8a7

Browse files
committed
Use stable async-std channels from async 1.9; this fixes the build. Drop the 'unstable' feature.
1 parent d9cef9b commit 37ef8a7

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ jobs:
2929
uses: actions-rs/cargo@v1
3030
with:
3131
command: test
32-
args: --features unstable

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@ description = "Experimental cooperative cancellation for async-std"
1010

1111
[dependencies]
1212
pin-project-lite = "0.1.0"
13-
async-std = "1.0"
14-
15-
[features]
16-
unstable = ["async-std/unstable"]
13+
async-std = "1.9"

src/lib.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
//! Experimental. The library works as is, breaking changes will bump major
66
//! version, but there are no guarantees of long-term support.
77
//!
8-
//! Additionally, this library uses unstable cargo feature feature of `async-std` and, for
9-
//! this reason, should be used like this:
10-
//!
11-
//! ```toml
12-
//! [dependencies.stop-token]
13-
//! version = "0.1.0"
14-
//! features = [ "unstable" ]
15-
//! ```
16-
//!
178
//! # Motivation
189
//!
1910
//! Rust futures come with a build-in cancellation mechanism: dropping a future
@@ -71,7 +62,7 @@ use std::pin::Pin;
7162
use std::task::{Context, Poll};
7263

7364
use async_std::prelude::*;
74-
use async_std::sync::{channel, Receiver, Sender};
65+
use async_std::channel::{self, Receiver, Sender};
7566
use pin_project_lite::pin_project;
7667

7768
enum Never {}
@@ -101,7 +92,7 @@ pub struct StopToken {
10192

10293
impl Default for StopSource {
10394
fn default() -> StopSource {
104-
let (sender, receiver) = channel::<Never>(1);
95+
let (sender, receiver) = channel::bounded::<Never>(1);
10596

10697
StopSource {
10798
_chan: sender,

tests/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::time::Duration;
22

3-
use async_std::{prelude::*, task, sync::channel};
3+
use async_std::{prelude::*, task, channel};
44

55
use stop_token::StopSource;
66

77
#[test]
88
fn smoke() {
99
task::block_on(async {
10-
let (sender, receiver) = channel::<i32>(10);
10+
let (sender, receiver) = channel::bounded::<i32>(10);
1111
let stop_source = StopSource::new();
1212
let task = task::spawn({
1313
let stop_token = stop_source.stop_token();
@@ -20,17 +20,17 @@ fn smoke() {
2020
}
2121
xs
2222
}});
23-
sender.send(1).await;
24-
sender.send(2).await;
25-
sender.send(3).await;
23+
assert!(sender.send(1).await.is_ok());
24+
assert!(sender.send(2).await.is_ok());
25+
assert!(sender.send(3).await.is_ok());
2626

2727
task::sleep(Duration::from_millis(250)).await;
2828
drop(stop_source);
2929
task::sleep(Duration::from_millis(250)).await;
3030

31-
sender.send(4).await;
32-
sender.send(5).await;
33-
sender.send(6).await;
31+
assert!(sender.send(4).await.is_ok());
32+
assert!(sender.send(5).await.is_ok());
33+
assert!(sender.send(6).await.is_ok());
3434
assert_eq!(task.await, vec![1, 2, 3]);
3535
})
3636
}

0 commit comments

Comments
 (0)