MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / compute_backoff

Function compute_backoff

nodedb/src/event/trigger/retry.rs:145–149  ·  view source on GitHub ↗

Compute exponential backoff: base * 2^(attempt-1), capped at MAX_BACKOFF.

(attempt: u32)

Source from the content-addressed store, hash-verified

143
144/// Compute exponential backoff: base * 2^(attempt-1), capped at MAX_BACKOFF.
145fn compute_backoff(attempt: u32) -> Duration {
146 let multiplier = 1u64 << (attempt.saturating_sub(1).min(20));
147 let delay = BASE_BACKOFF.saturating_mul(multiplier as u32);
148 delay.min(MAX_BACKOFF)
149}
150
151#[cfg(test)]
152mod tests {

Callers 2

enqueueMethod · 0.70
backoff_cappedFunction · 0.70

Calls

no outgoing calls

Tested by 1

backoff_cappedFunction · 0.56