@@ -12,13 +12,14 @@ use tokio::io::{AsyncRead, AsyncWrite};
12
12
13
13
use crate :: Recv ;
14
14
use crate :: body:: Body ;
15
+ use super :: super :: dispatch;
16
+ use crate :: common:: time:: Time ;
15
17
use crate :: common:: {
16
18
exec:: { BoxSendFuture , Exec } ,
17
19
task, Future , Pin , Poll ,
18
20
} ;
19
21
use crate :: proto;
20
- use crate :: rt:: Executor ;
21
- use super :: super :: dispatch;
22
+ use crate :: rt:: { Executor , Timer } ;
22
23
23
24
/// The sender side of an established connection.
24
25
pub struct SendRequest < B > {
44
45
#[ derive( Clone , Debug ) ]
45
46
pub struct Builder {
46
47
pub ( super ) exec : Exec ,
48
+ pub ( super ) timer : Time ,
47
49
h2_builder : proto:: h2:: client:: Config ,
48
50
}
49
51
@@ -114,7 +116,10 @@ where
114
116
/// before calling this method.
115
117
/// - Since absolute-form `Uri`s are not required, if received, they will
116
118
/// be serialized as-is.
117
- pub fn send_request ( & mut self , req : Request < B > ) -> impl Future < Output = crate :: Result < Response < Recv > > > {
119
+ pub fn send_request (
120
+ & mut self ,
121
+ req : Request < B > ,
122
+ ) -> impl Future < Output = crate :: Result < Response < Recv > > > {
118
123
let sent = self . dispatch . send ( req) ;
119
124
120
125
async move {
@@ -124,7 +129,7 @@ where
124
129
Ok ( Err ( err) ) => Err ( err) ,
125
130
// this is definite bug if it happens, but it shouldn't happen!
126
131
Err ( _canceled) => panic ! ( "dispatch dropped without returning error" ) ,
127
- }
132
+ } ,
128
133
Err ( _req) => {
129
134
tracing:: debug!( "connection was not ready" ) ;
130
135
@@ -207,6 +212,7 @@ impl Builder {
207
212
pub fn new ( ) -> Builder {
208
213
Builder {
209
214
exec : Exec :: Default ,
215
+ timer : Time :: Empty ,
210
216
h2_builder : Default :: default ( ) ,
211
217
}
212
218
}
@@ -220,6 +226,15 @@ impl Builder {
220
226
self
221
227
}
222
228
229
+ /// Provide a timer to execute background HTTP2 tasks.
230
+ pub fn timer < M > ( & mut self , timer : M ) -> & mut Builder
231
+ where
232
+ M : Timer + Send + Sync + ' static ,
233
+ {
234
+ self . timer = Time :: Timer ( Arc :: new ( timer) ) ;
235
+ self
236
+ }
237
+
223
238
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
224
239
/// stream-level flow control.
225
240
///
@@ -398,14 +413,13 @@ impl Builder {
398
413
tracing:: trace!( "client handshake HTTP/1" ) ;
399
414
400
415
let ( tx, rx) = dispatch:: channel ( ) ;
401
- let h2 =
402
- proto:: h2:: client:: handshake ( io, rx, & opts. h2_builder , opts. exec )
403
- . await ?;
416
+ let h2 = proto:: h2:: client:: handshake ( io, rx, & opts. h2_builder , opts. exec , opts. timer )
417
+ . await ?;
404
418
Ok ( (
405
419
SendRequest { dispatch : tx. unbound ( ) } ,
420
+ //SendRequest { dispatch: tx },
406
421
Connection { inner : ( PhantomData , h2) } ,
407
422
) )
408
423
}
409
424
}
410
425
}
411
-
0 commit comments