WaitToConnect returns only when port is ready to connect or canceled by context.
(ctx context.Context, bindAddr string, ports []int, interval time.Duration)
| 66 | |
| 67 | // WaitToConnect returns only when port is ready to connect or canceled by context. |
| 68 | func WaitToConnect(ctx context.Context, bindAddr string, ports []int, interval time.Duration) (err error) { |
| 69 | for { |
| 70 | continueCheckC: |
| 71 | select { |
| 72 | case <-ctx.Done(): |
| 73 | err = ctx.Err() |
| 74 | return |
| 75 | case <-time.After(interval): |
| 76 | for _, port := range ports { |
| 77 | addr := net.JoinHostPort(bindAddr, fmt.Sprint(port)) |
| 78 | if !testPortConnectable(addr, 100*time.Millisecond) { |
| 79 | goto continueCheckC |
| 80 | } |
| 81 | } |
| 82 | return |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // WaitForPorts returns only when port is ready to listen or canceled by context. |
| 88 | func WaitForPorts(ctx context.Context, bindAddr string, ports []int, interval time.Duration) (err error) { |