Skip to content
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

feat: Add retry with context #72

Merged
merged 1 commit into from Mar 8, 2024
Merged

feat: Add retry with context #72

merged 1 commit into from Mar 8, 2024

Conversation

Xuanwo
Copy link
Owner

@Xuanwo Xuanwo commented Mar 8, 2024

Close #49

use anyhow::anyhow;
use anyhow::Result;
use backon::ExponentialBuilder;
use backon::RetryableWithContext;

struct Test;

impl Test {
    async fn hello(&mut self) -> Result<usize> {
        Err(anyhow!("not retryable"))
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let mut test = Test;

    // (Test, Result<usize>)
    let (_, result) = {
        |mut v: Test| async {
            let res = v.hello().await;
            (v, res)
        }
    }
    .retry(&ExponentialBuilder::default())
    .context(test)
    .await;

    Ok(())
}

Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo merged commit d295d85 into main Mar 8, 2024
14 checks passed
@Xuanwo Xuanwo deleted the retry-with-context branch March 8, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

backon can't be used in along with &mut self
1 participant