File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed
Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " wait-service"
3- version = " 0.1.5 "
3+ version = " 0.1.6 "
44authors = [" Magic Len <len@magiclen.org>" ]
55edition = " 2021"
66repository = " https://github.com/magiclen/wait-service"
Original file line number Diff line number Diff line change @@ -87,19 +87,30 @@ async fn tcp(
8787
8888 let start = Instant :: now ( ) ;
8989
90- for ip in ips {
91- if timeout. is_zero ( ) {
92- while TcpStream :: connect ( ip) . await . is_err ( ) {
93- sleep ( SLEEP_INTERVAL ) . await ;
90+ if timeout. is_zero ( ) {
91+ ' outer: loop {
92+ for ip in ips. iter ( ) . cloned ( ) {
93+ if TcpStream :: connect ( ip) . await . is_ok ( ) {
94+ break ' outer;
95+ }
9496 }
95- } else {
96- while let Err ( err) = time:: timeout ( timeout, TcpStream :: connect ( ip) ) . await ? {
97- if Instant :: now ( ) - start > timeout {
98- return Err ( err. into ( ) ) ;
99- } else {
100- sleep ( SLEEP_INTERVAL ) . await ;
97+
98+ sleep ( SLEEP_INTERVAL ) . await ;
99+ }
100+ } else {
101+ ' outer_timeout: loop {
102+ for ip in ips. iter ( ) . cloned ( ) {
103+ match time:: timeout ( timeout, TcpStream :: connect ( ip) ) . await ? {
104+ Ok ( _) => break ' outer_timeout,
105+ Err ( err) => {
106+ if Instant :: now ( ) - start > timeout {
107+ return Err ( err. into ( ) ) ;
108+ }
109+ }
101110 }
102111 }
112+
113+ sleep ( SLEEP_INTERVAL ) . await ;
103114 }
104115 }
105116 }
You can’t perform that action at this time.
0 commit comments