Documentation ¶
Index ¶
- func AllClosed(channels ...<-chan struct{}) <-chan struct{}
- func AllDone(components ...module.ReadyDoneAware) <-chan struct{}
- func AllReady(components ...module.ReadyDoneAware) <-chan struct{}
- func CheckClosed(done <-chan struct{}) bool
- func DetypeSlice[T any](typedSlice []T) []any
- func LogProgress(msg string, total int, logger zerolog.Logger) func(currentIndex int)
- func MergeChannels(channels interface{}) interface{}
- func MergeReadyDone(components ...module.ReadyDoneAware) module.ReadyDoneAware
- func SampleN(n int, max, percentage float64) uint
- func WaitClosed(ctx context.Context, ch <-chan struct{}) error
- func WaitError(errChan <-chan error, done <-chan struct{}) error
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 DetypeSlice ¶ added in v0.29.0
DetypeSlice converts a typed slice containing any kind of elements into an untyped []any type, in effect removing the element type information from the slice. It is useful for passing data into structpb.NewValue, which accepts []any but not []T for any specific type T.
func LogProgress ¶ added in v0.29.0
LogProgress takes a total and return function such that when called with a 0-based index it prints the progress from 0% to 100% to indicate the index from 0 to (total - 1) has been processed. useful to report the progress of processing the index from 0 to (total - 1)
func MergeChannels ¶ added in v0.23.9
func MergeChannels(channels interface{}) interface{}
MergeChannels merges a list of channels into a single channel
func MergeReadyDone ¶ added in v0.29.0
func MergeReadyDone(components ...module.ReadyDoneAware) module.ReadyDoneAware
MergeReadyDone merges []module.ReadyDoneAware into one module.ReadyDoneAware.
func SampleN ¶ added in v0.31.0
SampleN computes a percentage of the given number 'n', and returns the result as an unsigned integer. If the calculated sample is greater than the provided 'max' value, it returns the ceil of 'max'. If 'n' is less than or equal to 0, it returns 0.
Parameters: - n: The input number, used as the base to compute the percentage. - max: The maximum value that the computed sample should not exceed. - percentage: The percentage (in range 0.0 to 1.0) to be applied to 'n'.
Returns: - The computed sample as an unsigned integer, with consideration to the given constraints.
func WaitClosed ¶ added in v0.23.9
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
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.