-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexey Kalita <kalita.alexey@outlook.com>
- Loading branch information
1 parent
ac0ad74
commit 7567334
Showing
8 changed files
with
510 additions
and
96 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
"name": "wonderland", | ||
"accounts": {}, | ||
"asset_definitions": {}, | ||
"metadata": {} | ||
"metadata": {} | ||
} | ||
} | ||
} | ||
|
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
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,41 @@ | ||
/// Encapsulates the retry period that is calculated as `min_period + 2 ^ min(exponent, max_exponent)` | ||
pub struct RetryPeriod { | ||
/// The minimum period | ||
min_period: u64, | ||
/// The maximum exponent | ||
max_exponent: u8, | ||
/// The current exponent | ||
exponent: u8, | ||
} | ||
|
||
impl RetryPeriod { | ||
pub const DEFAULT_MIN_PERIOD: u64 = 1; | ||
pub const DEFAULT_MAX_EXPONENT: u8 = 4; | ||
|
||
/// Constructs a new object | ||
pub fn new(min_period: u64, max_exponent: u8) -> Self { | ||
Self { | ||
min_period, | ||
max_exponent, | ||
exponent: 0, | ||
} | ||
} | ||
|
||
/// Increases the exponent if it isn't at its maximum | ||
pub fn increase_exponent(&mut self) { | ||
if self.exponent < self.max_exponent { | ||
self.exponent += 1; | ||
} | ||
} | ||
|
||
/// Returns the period | ||
pub fn period(&mut self) -> u64 { | ||
self.min_period + 2_u64.saturating_mul(self.exponent.into()) | ||
} | ||
} | ||
|
||
impl Default for RetryPeriod { | ||
fn default() -> Self { | ||
Self::new(Self::DEFAULT_MIN_PERIOD, Self::DEFAULT_MAX_EXPONENT) | ||
} | ||
} |
Oops, something went wrong.