-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to get Retry to work #50
Comments
Thanks for reaching out! Here are some problems here:
I have tested the following code locally, may worth a look: use backon::ConstantBuilder;
use backon::Retryable;
use std::error::Error;
use std::thread;
use std::time::Duration;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// Note here, use `foo` instead of `foo()`
let _ = foo.retry(&ConstantBuilder::default()).await?;
Ok(())
}
async fn foo() -> Result<(), Box<dyn Error + Send + Sync>> {
async { thread::sleep(Duration::from_secs(1)) }.await;
Ok(())
} |
Ah, Ok. thanks. And what if |
We need to capture it in an async closure, something like: let f = || async { foo(xxx).await }
f.retry().await |
Magnificent. You're a star 🌟 I had tried some of that; missed out the Thank you again. |
Thanks for posting this, I have to use it like this let upsert_res = (|| async {
current_epoch_store
.clone()
.upsert_current_epoch(epoch_info.epoch)
.await
})
.retry(&ConstantBuilder::default())
.await; |
@Xuanwo maybe this recipe could be added to the rustdocs? I also was confused by a similar compiler error . |
Makes sense, let me add them. |
I'm sure I'm doing something completely stupid, but just can't work it out. In my reproduction of what I'm experiencing in my real project, I just can't get backon working with my future.
results in the following error
I'm completely baffled. I've tried adding in anyhow, thinking it may be doing some magic, but get the same error. What am I doing wrong?
The text was updated successfully, but these errors were encountered: