File tree Expand file tree Collapse file tree 4 files changed +11
-24
lines changed Expand file tree Collapse file tree 4 files changed +11
-24
lines changed Original file line number Diff line number Diff line change 29
29
uses : actions-rs/cargo@v1
30
30
with :
31
31
command : test
32
- args : --features unstable
Original file line number Diff line number Diff line change @@ -10,7 +10,4 @@ description = "Experimental cooperative cancellation for async-std"
10
10
11
11
[dependencies ]
12
12
pin-project-lite = " 0.1.0"
13
- async-std = " 1.0"
14
-
15
- [features ]
16
- unstable = [" async-std/unstable" ]
13
+ async-std = " 1.9"
Original file line number Diff line number Diff line change 5
5
//! Experimental. The library works as is, breaking changes will bump major
6
6
//! version, but there are no guarantees of long-term support.
7
7
//!
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
- //!
17
8
//! # Motivation
18
9
//!
19
10
//! Rust futures come with a build-in cancellation mechanism: dropping a future
@@ -71,7 +62,7 @@ use std::pin::Pin;
71
62
use std:: task:: { Context , Poll } ;
72
63
73
64
use async_std:: prelude:: * ;
74
- use async_std:: sync :: { channel , Receiver , Sender } ;
65
+ use async_std:: channel :: { self , Receiver , Sender } ;
75
66
use pin_project_lite:: pin_project;
76
67
77
68
enum Never { }
@@ -101,7 +92,7 @@ pub struct StopToken {
101
92
102
93
impl Default for StopSource {
103
94
fn default ( ) -> StopSource {
104
- let ( sender, receiver) = channel :: < Never > ( 1 ) ;
95
+ let ( sender, receiver) = channel:: bounded :: < Never > ( 1 ) ;
105
96
106
97
StopSource {
107
98
_chan : sender,
Original file line number Diff line number Diff line change 1
1
use std:: time:: Duration ;
2
2
3
- use async_std:: { prelude:: * , task, sync :: channel} ;
3
+ use async_std:: { prelude:: * , task, channel} ;
4
4
5
5
use stop_token:: StopSource ;
6
6
7
7
#[ test]
8
8
fn smoke ( ) {
9
9
task:: block_on ( async {
10
- let ( sender, receiver) = channel :: < i32 > ( 10 ) ;
10
+ let ( sender, receiver) = channel:: bounded :: < i32 > ( 10 ) ;
11
11
let stop_source = StopSource :: new ( ) ;
12
12
let task = task:: spawn ( {
13
13
let stop_token = stop_source. stop_token ( ) ;
@@ -20,17 +20,17 @@ fn smoke() {
20
20
}
21
21
xs
22
22
} } ) ;
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 ( ) ) ;
26
26
27
27
task:: sleep ( Duration :: from_millis ( 250 ) ) . await ;
28
28
drop ( stop_source) ;
29
29
task:: sleep ( Duration :: from_millis ( 250 ) ) . await ;
30
30
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 ( ) ) ;
34
34
assert_eq ! ( task. await , vec![ 1 , 2 , 3 ] ) ;
35
35
} )
36
36
}
You can’t perform that action at this time.
0 commit comments