-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from flub/stable-async-std
Support stable async-std
- Loading branch information
Showing
4 changed files
with
24 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,3 @@ jobs: | |
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --features unstable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "stop-token" | ||
version = "0.1.2" | ||
version = "0.2.0" | ||
authors = ["Aleksey Kladov <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -9,8 +9,5 @@ repository = "https://github.com/async-rs/stop-token" | |
description = "Experimental cooperative cancellation for async-std" | ||
|
||
[dependencies] | ||
pin-project-lite = "0.1.0" | ||
async-std = "1.0" | ||
|
||
[features] | ||
unstable = ["async-std/unstable"] | ||
pin-project-lite = "0.2.0" | ||
async-std = "1.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
use std::time::Duration; | ||
|
||
use async_std::{prelude::*, task, sync::channel}; | ||
use async_std::prelude::*; | ||
|
||
use async_std::channel; | ||
use async_std::task; | ||
|
||
use stop_token::StopSource; | ||
|
||
#[test] | ||
fn smoke() { | ||
task::block_on(async { | ||
let (sender, receiver) = channel::<i32>(10); | ||
let (sender, receiver) = channel::bounded::<i32>(10); | ||
let stop_source = StopSource::new(); | ||
let task = task::spawn({ | ||
let stop_token = stop_source.stop_token(); | ||
let receiver = receiver.clone(); | ||
async move { | ||
let mut xs = Vec::new(); | ||
let mut stream = stop_token.stop_stream(receiver); | ||
while let Some(x) = stream.next().await { | ||
xs.push(x) | ||
let mut xs = Vec::new(); | ||
let mut stream = stop_token.stop_stream(receiver); | ||
while let Some(x) = stream.next().await { | ||
xs.push(x) | ||
} | ||
xs | ||
} | ||
xs | ||
}}); | ||
sender.send(1).await; | ||
sender.send(2).await; | ||
sender.send(3).await; | ||
}); | ||
sender.send(1).await.unwrap(); | ||
sender.send(2).await.unwrap(); | ||
sender.send(3).await.unwrap(); | ||
|
||
task::sleep(Duration::from_millis(250)).await; | ||
drop(stop_source); | ||
task::sleep(Duration::from_millis(250)).await; | ||
|
||
sender.send(4).await; | ||
sender.send(5).await; | ||
sender.send(6).await; | ||
sender.send(4).await.unwrap(); | ||
sender.send(5).await.unwrap(); | ||
sender.send(6).await.unwrap(); | ||
assert_eq!(task.await, vec![1, 2, 3]); | ||
}) | ||
} |