File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ async fn main() {
38
38
println ! (
39
39
"Green Thread 1 - {} -> {:?} ended: {:?}" ,
40
40
"health.check()" ,
41
- thc. check( context:: with_timeout ( 20 * 1000 * 1000 ) , & req)
41
+ thc. check( context:: with_duration ( core :: time :: Duration :: from_millis ( 20 ) ) , & req)
42
42
. await ,
43
43
now. elapsed( ) ,
44
44
) ;
Original file line number Diff line number Diff line change 4
4
//
5
5
6
6
use crate :: proto:: KeyValue ;
7
+ use core:: time:: Duration ;
7
8
use std:: collections:: HashMap ;
8
-
9
9
#[ derive( Clone , Default , Debug ) ]
10
10
pub struct Context {
11
11
pub metadata : HashMap < String , Vec < String > > ,
@@ -18,6 +18,11 @@ pub fn with_timeout(i: i64) -> Context {
18
18
..Default :: default ( )
19
19
}
20
20
}
21
+ ///With_timeout is not friendly enough to external interfaces
22
+ ///Keep with_timeout for forward compatibility
23
+ pub fn with_duration ( du : Duration ) -> Context {
24
+ with_timeout ( du. as_nanos ( ) as i64 )
25
+ }
21
26
22
27
pub fn with_metadata ( md : HashMap < String , Vec < String > > ) -> Context {
23
28
Context {
@@ -131,7 +136,7 @@ mod tests {
131
136
assert_eq ! ( 0 , ctx. timeout_nano) ;
132
137
assert_eq ! ( ctx. metadata. len( ) , 0 ) ;
133
138
134
- let mut ctx = context:: with_timeout ( 99 ) ;
139
+ let mut ctx = context:: with_duration ( core :: time :: Duration :: from_nanos ( 99 ) ) ;
135
140
assert_eq ! ( 99 , ctx. timeout_nano) ;
136
141
assert_eq ! ( ctx. metadata. len( ) , 0 ) ;
137
142
You can’t perform that action at this time.
0 commit comments