Function race_connect
pub async fn race_connect<S, C, F, Fut>(
candidates: S,
max_in_flight: usize,
dial: F,
) -> Result<(SocketAddr, C), Box<dyn Error + Sync + Send>>Available on crate feature
net only.Expand description
Race connection attempts over a stream of candidate SocketAddresses.
Pulls candidates from candidates in order (e.g. happy-eyeballs order from a
ConnectorTargetStream), keeps up to max_in_flight dials racing
concurrently via dial, and returns the first successful connection together
with the address it connected to. If every candidate fails (to resolve or to
connect), every failure is returned in an ErrorList, each dial failure
with its address as context. The last failure is the primary one, so the
error classifies as before: when that failure is classified (it carries a
ConnectionError or a timeout), the returned error is a ConnectionError
with that classification. A single unclassified failure is returned as itself.