util

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: AGPL-3.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllClosed added in v0.23.2

func AllClosed(channels ...<-chan struct{}) <-chan struct{}

AllClosed returns a channel that is closed when all input channels are closed.

func AllDone

func AllDone(components ...module.ReadyDoneAware) <-chan struct{}

AllDone calls Done on all input components and returns a channel that is closed when all input components are done.

func AllReady

func AllReady(components ...module.ReadyDoneAware) <-chan struct{}

AllReady calls Ready on all input components and returns a channel that is closed when all input components are ready.

func CheckClosed added in v0.23.9

func CheckClosed(done <-chan struct{}) bool

CheckClosed checks if the provided channel has a signal or was closed. Returns true if the channel was signaled/closed, otherwise, returns false.

This is intended to reduce boilerplate code when multiple channel checks are required because missed signals could cause safety issues.

func MergeChannels added in v0.23.9

func MergeChannels(channels interface{}) interface{}

MergeChannels merges a list of channels into a single channel

func WaitClosed added in v0.23.9

func WaitClosed(ctx context.Context, ch <-chan struct{}) error

WaitClosed waits for either a signal/close on the channel or for the context to be cancelled Returns nil if the channel was signalled/closed before returning, otherwise, it returns the context error.

This handles the corner case where the context is cancelled at the same time that the channel is closed, and the Done case was selected. This is intended for situations where ignoring a signal can cause safety issues.

func WaitError added in v0.23.9

func WaitError(errChan <-chan error, done <-chan struct{}) error

WaitError waits for either an error on the error channel or the done channel to close Returns an error if one is received on the error channel, otherwise it returns nil

This handles a race condition where the done channel could have been closed as a result of an irrecoverable error being thrown, so that when the scheduler yields control back to this goroutine, both channels are available to read from. If the done case happens to be chosen at random to proceed instead of the error case, then we would return without error which could result in unsafe continuation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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