-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support ?
and return
in the decorated function
#4
Merged
Brendan-Blanchard
merged 5 commits into
Brendan-Blanchard:master
from
haxorcize:support_try_and_return
May 21, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adf088b
First commit:
haxorcize 05507c9
Basic test showing that retry works on try with Result<_, _>, but fai…
brendano257 6b131cf
When converting try operators into a match expression, we use into() …
haxorcize ff3de9e
Fix wait timing; update tests; update docs; bump version
brendano257 9044c61
Modify consuming function ui test; output is dependent on compiler ve…
brendano257 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! This example tests a backoff configuration using a function that returns false for if it should | ||
//! retry, thus resulting in no retries at all. | ||
use std::num::ParseIntError; | ||
use std::str::FromStr; | ||
use retry_if::{retry, ExponentialBackoffConfig}; | ||
use std::time::Duration; | ||
use tokio::time::Instant; | ||
|
||
const BACKOFF_CONFIG: ExponentialBackoffConfig = ExponentialBackoffConfig { | ||
max_retries: 5, | ||
t_wait: Duration::from_secs(1), | ||
backoff: 2.0, | ||
t_wait_max: None, | ||
backoff_max: None, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_retry_with_try_operator_on_result() { | ||
fn retry_if(_: &Result<i32, ParseIntError>) -> bool { | ||
false | ||
} | ||
|
||
#[retry(BACKOFF_CONFIG, retry_if)] | ||
async fn method(int: &str) -> Result<i32, ParseIntError> { | ||
return Ok(i32::from_str(int)?); | ||
} | ||
|
||
let result = method("3").await; | ||
assert_eq!(Ok(3), result); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_retry_with_try_operator_on_option() { | ||
fn retry_if(_: &Result<i32, ParseIntError>) -> bool { | ||
false | ||
} | ||
|
||
#[retry(BACKOFF_CONFIG, retry_if)] | ||
async fn method(int: &str) -> Option<i32> { | ||
return Some(i32::from_str(int).ok()?); | ||
} | ||
|
||
let result = method("3").await; | ||
assert_eq!(Some(3), result); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails because the usage of
?
on anOption
gets modified by the block modifier, looking like below: