synctrack

package
v0.29.10 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 3 Imported by: 4

Documentation

Overview

Package synctrack contains utilities for helping controllers track whether they are "synced" or not, that is, whether they have processed all items from the informer's initial list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncTracker

type AsyncTracker[T comparable] struct {
	UpstreamHasSynced func() bool
	// contains filtered or unexported fields
}

AsyncTracker helps propagate HasSynced in the face of multiple worker threads.

func (*AsyncTracker[T]) Finished

func (t *AsyncTracker[T]) Finished(key T)

Finished should be called when finished processing a key which was part of the initial list. Since keys are tracked individually, nothing bad happens if you call Finished without a corresponding call to Start. This makes it easier to use this in combination with e.g. queues which don't make it easy to plumb through the isInInitialList boolean.

func (*AsyncTracker[T]) HasSynced

func (t *AsyncTracker[T]) HasSynced() bool

HasSynced returns true if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*AsyncTracker[T]) Start

func (t *AsyncTracker[T]) Start(key T)

Start should be called prior to processing each key which is part of the initial list.

type Lazy

type Lazy[T any] struct {
	Evaluate func() (T, error)
	// contains filtered or unexported fields
}

Lazy defers the computation of `Evaluate` to when it is necessary. It is possible that Evaluate will be called in parallel from multiple goroutines.

func (*Lazy[T]) Get

func (z *Lazy[T]) Get() (T, error)

Get should be called to get the current result of a call to Evaluate. If the current cached value is stale (due to a call to Notify), then Evaluate will be called synchronously. If subsequent calls to Get happen (without another Notify), they will all wait for the same return value.

Error returns are not cached and will cause multiple calls to evaluate!

func (*Lazy[T]) Notify

func (z *Lazy[T]) Notify()

Notify should be called when something has changed necessitating a new call to Evaluate.

type SingleFileTracker

type SingleFileTracker struct {
	UpstreamHasSynced func() bool
	// contains filtered or unexported fields
}

SingleFileTracker helps propagate HasSynced when events are processed in order (i.e. via a queue).

func (*SingleFileTracker) Finished

func (t *SingleFileTracker) Finished()

Finished should be called when finished processing a key which was part of the initial list. You must never call Finished() before (or without) its corresponding Start(), that is a logic error that could cause HasSynced to return a wrong value. To help you notice this should it happen, Finished() will panic if the internal counter goes negative.

func (*SingleFileTracker) HasSynced

func (t *SingleFileTracker) HasSynced() bool

HasSynced returns true if the source is synced and every key present in the initial list has been processed. This relies on the source not considering itself synced until *after* it has delivered the notification for the last key, and that notification handler must have called Start.

func (*SingleFileTracker) Start

func (t *SingleFileTracker) Start()

Start should be called prior to processing each key which is part of the initial list.

Jump to

Keyboard shortcuts

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