Documentation ¶
Overview ¶
Package groupcancel contains helpers to cancel groups of requests when enough finish.
The main type is the Context type which takes a total number of requests, the fraction of the non-failed requests that must succeed before the rest are canceled, and an extra wait fraction to multiply by the time it took to succeed that will be waited before the rest are canceled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context keeps track of a set of operations and helps cancel long tails.
func NewContext ¶
func NewContext(ctx context.Context, total int, cancelAt float64, extraWait float64) (*Context, func())
NewContext constructs a Context which implements context.Context and allows one to cancel it based on the speed at which some operations completed.
When the number of successful operations vs the number of non-bad remaining operations exceeds the ratio to cancel at, the Context will cancel after waiting an amount of time computed by the amount of time it took so far multiplied by extraWait.
It returns the Context and a cancel func that must be called, much like the context api.