
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
github.com/cloudflare/backoff
This package implements the backoff strategy described in the AWS
Architecture Blog article
"Exponential Backoff And Jitter". Essentially,
the backoff has an interval time.Duration
; the nth call
to backoff will return an a time.Duration
that is 2 n *
interval. If jitter is enabled (which is the default behaviour), the
duration is a random value between 0 and 2 n * interval.
The backoff is configured with a maximum duration that will not be
exceeded; e.g., by default, the longest duration returned is
backoff.DefaultMaxDuration
.
A Backoff
is initialised with a call to New
. Using zero values
causes it to use DefaultMaxDuration
and DefaultInterval
as the
maximum duration and interval.
package something
import "github.com/cloudflare/backoff"
func retryable() {
b := backoff.New(0, 0)
for {
err := someOperation()
if err == nil {
break
}
log.Printf("error in someOperation: %v", err)
<-time.After(b.Duration())
}
log.Printf("succeeded after %d tries", b.Tries()+1)
b.Reset()
}
It can also be used to rate limit code that should retry infinitely, but which does not
use Backoff
itself.
package something
import (
"time"
"github.com/cloudflare/backoff"
)
func retryable() {
b := backoff.New(0, 0)
b.SetDecay(30 * time.Second)
for {
// b will reset if someOperation returns later than
// the last call to b.Duration() + 30s.
err := someOperation()
if err == nil {
break
}
log.Printf("error in someOperation: %v", err)
<-time.After(b.Duration())
}
}
NewWithoutJitter
creates a Backoff that doesn't use jitter.The default behaviour is controlled by two variables:
DefaultInterval
sets the base interval for backoffs created with
the zero time.Duration
value in the Interval
field.DefaultMaxDuration
sets the maximum duration for backoffs created
with the zero time.Duration
value in the MaxDuration
field.FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.