pub async fn poll_until_with<T, F, Fut>(
opts: PollOpts,
what: impl Display + Send,
poll: F,
) -> Result<T>Expand description
Calls poll until it returns a value, with the timeout and interval of opts.
The first poll starts immediately, and every further poll opts.interval after the previous
one returned None. The wait ends opts.timeout after the call: a poll that is still running
is dropped, and there is no final poll at the deadline, so a condition that only becomes true
during the last interval is reported as timed out, and an interval at least as long as the
timeout polls once.
Returns the value of the first poll that returns Some, the first error returned by poll, or
an error naming what and the timeout, e.g. timed out after 30s waiting for block 1.
what is held across awaits, so it must be Send for the returned future to be Send. This
rules out format_args!, use format! instead.
let receipt = poll_until_with(
PollOpts { interval: Duration::from_secs(1), ..Default::default() },
format!("receipt of transaction {tx_hash}"),
|| async { Ok(provider.get_transaction_receipt(tx_hash).await?) },
)
.await?;