Source File
context.go
Belonging Package
github.com/cenkalti/backoff/v4
package backoff
import (
)
// BackOffContext is a backoff policy that stops retrying after the context
// is canceled.
type BackOffContext interface { // nolint: golint
BackOff
Context() context.Context
}
type backOffContext struct {
BackOff
ctx context.Context
}
// WithContext returns a BackOffContext with context ctx
//
// ctx must not be nil
func ( BackOff, context.Context) BackOffContext { // nolint: golint
if == nil {
panic("nil context")
}
if , := .(*backOffContext); {
return &backOffContext{
BackOff: .BackOff,
ctx: ,
}
}
return &backOffContext{
BackOff: ,
ctx: ,
}
}
func ( BackOff) context.Context {
if , := .(BackOffContext); {
return .Context()
}
if , := .(*backOffTries); {
return (.delegate)
}
return context.Background()
}
func ( *backOffContext) () context.Context {
return .ctx
}
func ( *backOffContext) () time.Duration {
select {
case <-.ctx.Done():
return Stop
default:
return .BackOff.NextBackOff()
}
}
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |