groupcancel

package
v0.28.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2019 License: AGPL-3.0 Imports: 3 Imported by: 0

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.

func (*Context) Failure

func (c *Context) Failure()

Failure tells the Context that one of the operations was a failure.

func (*Context) Success

func (c *Context) Success()

Success tells the Context that one of the operations was successful.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL