I have to retry an async function- handle_message
& I'm using the retry crate for it (version "1.2.1"). But the second argument is a closure.
use retry::{retry, delay::Fixed};
retry(Fixed::from_millis(10000).take(3), || async {
let message = handle_message(my_message.clone()).await;
match message {
Ok(()) => info!("Message successfully registered"),
Err(e) => {
// For certain errors likely to resolve if we wait a bit, we schedule a retry
if e.is_code(EC::MyErrorCode, true)
{
debug!("Handling message error- {:?}", e);
return Err(format!("Dkg message w/ error: {:?}", e));
}
}
}
Ok(()) // Don't try any other errors
});
I'm getting the following error:
the trait bound `OperationResult<_, _>: From<[async block@src/my_file.rs:xx:xx]>` is not satisfied
the trait `From<std::result::Result<T, E>>` is implemented for `OperationResult<T, E>`
required for `[async block@src/my_file.rs:xx:xx]` to implement `Into<OperationResult<_, _>>`
I tried return from the async closure OperationResult::Ok/Err
as well instead Result::Ok/Err
but I still get the same error.
Is it even possible to use an async function inside the retry block?