@@ -59,33 +59,28 @@ where
59
59
}
60
60
61
61
fn call ( & mut self , dst : Uri ) -> Self :: Future {
62
+ let connect_timeout = self . connect_timeout ;
62
63
let read_timeout = self . read_timeout ;
63
64
let write_timeout = self . write_timeout ;
64
65
let connecting = self . connector . call ( dst) ;
65
66
66
- if self . connect_timeout . is_none ( ) {
67
- let fut = async move {
68
- let io = connecting. await . map_err ( Into :: into) ?;
69
-
70
- let mut tm = TimeoutConnectorStream :: new ( TimeoutStream :: new ( io) ) ;
71
- tm. set_read_timeout ( read_timeout) ;
72
- tm. set_write_timeout ( write_timeout) ;
73
- Ok ( Box :: pin ( tm) )
74
- } ;
75
-
76
- return Box :: pin ( fut) ;
77
- }
78
-
79
- let connect_timeout = self . connect_timeout . expect ( "Connect timeout should be set" ) ;
80
- let timeout = timeout ( connect_timeout, connecting) ;
81
-
82
67
let fut = async move {
83
- let connecting = timeout
84
- . await
85
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: TimedOut , e) ) ?;
86
- let io = connecting. map_err ( Into :: into) ?;
68
+ let stream = match connect_timeout {
69
+ None => {
70
+ let io = connecting. await . map_err ( Into :: into) ?;
71
+ TimeoutStream :: new ( io)
72
+ }
73
+ Some ( connect_timeout) => {
74
+ let timeout = timeout ( connect_timeout, connecting) ;
75
+ let connecting = timeout
76
+ . await
77
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: TimedOut , e) ) ?;
78
+ let io = connecting. map_err ( Into :: into) ?;
79
+ TimeoutStream :: new ( io)
80
+ }
81
+ } ;
87
82
88
- let mut tm = TimeoutConnectorStream :: new ( TimeoutStream :: new ( io ) ) ;
83
+ let mut tm = TimeoutConnectorStream :: new ( stream ) ;
89
84
tm. set_read_timeout ( read_timeout) ;
90
85
tm. set_write_timeout ( write_timeout) ;
91
86
Ok ( Box :: pin ( tm) )
0 commit comments