pub async fn retry_async<T, Op, Fut, IsRetryable, E>(
policy: &NetworkRetryPolicy,
label: Option<&'static str>,
op: Op,
is_retryable: IsRetryable,
) -> Result<T, E>Expand description
Executes op with reconnect/backoff according to policy.
label, if Some, is emitted as a structured component tracing field
and in the retry log message text so operators can identify which component
is retrying (e.g., ws-producer: transient error — retrying). Pass None
for the pre-0.14 backwards-compatible unlabeled path.
is_retryable classifies errors: retryable errors are retried, permanent
errors are not.
§Security note: error Display is logged at WARN level
On every retry, the error’s Display representation
is emitted via tracing::warn! for operator visibility during connection
retries. Callers MUST sanitize errors before returning them from op if
they may contain sensitive content such as connection strings, embedded
credentials, or host‑port pairs. Sanitization belongs at the source — in
the IO call whose error is wrapped — not here.
This log call is intentional and should not be removed: it provides the only diagnostic signal that a networked component is retrying and why.
§Example
let result = retry_async(
&config.reconnect,
Some("ws-producer"),
|| async move { connect_to_server().await },
|err: &CamelError| matches!(err, CamelError::Io(_)),
).await?;