-
Notifications
You must be signed in to change notification settings - Fork 8
Support stable async-std #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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" | ||
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::*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flub I was wondering why the change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mixing multiple levels of of imports quickly becomes confusing to me, that is i avoid having to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, just a style question and I was simply curious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the downside to this however is that it makes the diff harder to read There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you stick to that style all following diffs are more readable. If you don't every single non-trivial diff becomes harder to read. this is all bikeshedding of course and depends on personal taste :) i wish cargo-fmt had much stricter formatting rules around imports instead of allowing so many variations, it would avoid this bikeshedding. |
||
|
||
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]); | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about this change. If I understand cargo dependency resolution,
async-std = "1.0"
is short forasync-std="^1.0"
, which in this case would resolve toasync-std="1.9"
since:^1 := >=1.0.0, <2.0.0
. So I think this version bump is superfluous so semver will evaluate to the latest1.x
release, namely1.9
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.8 is the earliest version this can support. setting it like this is equivalent to
^1.8
or>=1.8.0 <2.0.0
. As this is a library that means users can themselves say for exampleasync-std = "^1.18"
in their own cargo.toml and this library will not force another duplicate version of async-std to be compiled in as that version is still compatible here.If we would set this to
^1
then someone depending on this could say= 1.3.0
and we'd get that version here and it would break.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i'm missing something about dependency resolution here. When I set
async-std="1.0"
cargo downloads1.9
. I guess I don't understand how to tell cargo to use less than1.9
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your binary says
async-std >= 1.0.0, < 2.0.0
and you also depend on stop-token which saysasync-std >= 1.8.0, < 2.0.0
. As that's the only input to cargo's dependency resolver it decides it also prefers the most recent version and it resolves this toasync-std 1.9.0
which satisfies all those constraints.If you want cargo to use something older than 1.9 you need to tell it to do that in your Cargo.toml. Set
async-std: <1.9
probably with some other constraints added. If you are asking forasync-std < 1.8
but do ask forstop-token >= 0.2
then cargo will build 2 versions of async-std into your binary.