syncutil

package
v3.9.9 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackoffWithContext

func BackoffWithContext(ctx context.Context, backoff wait.Backoff, condition wait.ConditionFunc) error

BackoffWithContext repeats a condition check with exponential backoff, exiting early if the provided context is canceled.

It repeatedly checks the condition and then sleeps, using `backoff.Step()` to determine the length of the sleep and adjust Duration and Steps. Stops and returns as soon as: 1. the condition check returns true or an error, or 2. the context is canceled. In case (1) the returned error is what the condition function returned. In all other cases, ErrWaitTimeout is returned.

Adapted from wait.ExponentialBackoff in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/wait/wait.go

func WaitAll

func WaitAll(w ...Waiter) error

WaitAll waits (blocks) for multiple Wait()-ables and returns the first non-nil error.

Types

type SingleRunner

type SingleRunner struct {
	// contains filtered or unexported fields
}

SingleRunner wraps an errgroup to run keyed goroutines as singletons. Keys are single-use and subsequent usage to schedule will be silently ignored. Goroutines can be individually canceled provided they respect the context passed to them.

func RunnerWithContext

func RunnerWithContext(ctx context.Context) *SingleRunner

RunnerWithContext returns an initialized SingleRunner. The provided context is used as the parent of subsequently scheduled goroutines.

func (*SingleRunner) Cancel

func (s *SingleRunner) Cancel(key string)

Cancel cancels a keyed goroutine if it exists.

func (*SingleRunner) Go

func (s *SingleRunner) Go(ctx context.Context, key string, f func(context.Context) error)

Go schedules the provided function on a new goroutine if the provided key has not been used for scheduling before.

func (*SingleRunner) Wait

func (s *SingleRunner) Wait() error

Wait waits for all goroutines managed by the SingleRunner to complete. Returns the first error returned from a managed goroutine, or nil.

type SyncBool

type SyncBool struct {
	// contains filtered or unexported fields
}

SyncBool represents a synchronized boolean flag. Its methods are safe to call concurrently.

func (*SyncBool) Get

func (b *SyncBool) Get() bool

Get returns the current value of the flag.

func (*SyncBool) Set

func (b *SyncBool) Set(v bool)

Set sets the values of the flag.

type Waiter

type Waiter interface {
	Wait() error
}

Jump to

Keyboard shortcuts

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