Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "time" "github.com/joshbohde/congestion" ) func doRequest() error { return nil } func main() { const ( HighPriority = 100 ) // A limiter can be used to manage concurrent access to a rate limited resource limiter := congestion.New(congestion.Config{ Capacity: 10, MaxLimit: 10, }) // backoff manages a single retryable request with priority backoff := congestion.Backoff{ Step: 100 * time.Millisecond, Limiter: &limiter, Priority: HighPriority, } defer backoff.Close() // Try the request until either it succeeds, or the context is canceled for backoff.Try(context.Background()) { // Make some sort of request to the rate limited resource err := doRequest() // If this error signals we are overloading the server, we'll retry if err != nil { continue } // Otherwise return return } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Dropped = errors.New("dropped")
Dropped is the error that will be returned if this token is dropped
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct { Step time.Duration Limiter *Limiter Priority int Error error // contains filtered or unexported fields }
Backoff implements exponential backoff retries on top of a Limiter
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func (*Limiter) Acquire ¶
Acquire a Lock with FIFO ordering, respecting the context. Returns an error it fails to acquire.
Click to show internal directories.
Click to hide internal directories.