@@ -12,13 +12,14 @@ use tokio::io::{AsyncRead, AsyncWrite};
1212
1313use crate :: Recv ;
1414use crate :: body:: Body ;
15+ use super :: super :: dispatch;
16+ use crate :: common:: time:: Time ;
1517use crate :: common:: {
1618 exec:: { BoxSendFuture , Exec } ,
1719 task, Future , Pin , Poll ,
1820} ;
1921use crate :: proto;
20- use crate :: rt:: Executor ;
21- use super :: super :: dispatch;
22+ use crate :: rt:: { Executor , Timer } ;
2223
2324/// The sender side of an established connection.
2425pub struct SendRequest < B > {
4445#[ derive( Clone , Debug ) ]
4546pub struct Builder {
4647 pub ( super ) exec : Exec ,
48+ pub ( super ) timer : Time ,
4749 h2_builder : proto:: h2:: client:: Config ,
4850}
4951
@@ -114,7 +116,10 @@ where
114116 /// before calling this method.
115117 /// - Since absolute-form `Uri`s are not required, if received, they will
116118 /// 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 > > > {
118123 let sent = self . dispatch . send ( req) ;
119124
120125 async move {
@@ -124,7 +129,7 @@ where
124129 Ok ( Err ( err) ) => Err ( err) ,
125130 // this is definite bug if it happens, but it shouldn't happen!
126131 Err ( _canceled) => panic ! ( "dispatch dropped without returning error" ) ,
127- }
132+ } ,
128133 Err ( _req) => {
129134 tracing:: debug!( "connection was not ready" ) ;
130135
@@ -207,6 +212,7 @@ impl Builder {
207212 pub fn new ( ) -> Builder {
208213 Builder {
209214 exec : Exec :: Default ,
215+ timer : Time :: Empty ,
210216 h2_builder : Default :: default ( ) ,
211217 }
212218 }
@@ -220,6 +226,15 @@ impl Builder {
220226 self
221227 }
222228
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+
223238 /// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
224239 /// stream-level flow control.
225240 ///
@@ -398,14 +413,13 @@ impl Builder {
398413 tracing:: trace!( "client handshake HTTP/1" ) ;
399414
400415 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 ?;
404418 Ok ( (
405419 SendRequest { dispatch : tx. unbound ( ) } ,
420+ //SendRequest { dispatch: tx },
406421 Connection { inner : ( PhantomData , h2) } ,
407422 ) )
408423 }
409424 }
410425}
411-
0 commit comments