Repository: kubernetes/kubernetes
File: staging/src/k8s.io/client-go/tools/cache/the_real_fifo.go (Go)

Code before:
	"k8s.io/apimachinery/pkg/util/sets"
	utiltrace "k8s.io/utils/trace"
)

// RealFIFOOptions is the configuration parameters for RealFIFO.
type RealFIFOOptions struct {
	// KeyFunction is used to figure out what key an object should have. (It's
	// exposed in the returned RealFIFO's keyOf() method, with additional
	// handling around deleted objects and queue state).
	// Optional, the default is MetaNamespaceKeyFunc.
	KeyFunction KeyFunc

	// KnownObjects is expected to return a list of keys that the consumer of
	// this queue "knows about". It is used to decide which items are missing
	// when Replace() is called; 'Deleted' deltas are produced for the missing items.
	// KnownObjects is required.
	KnownObjects KeyListerGetter

	// If set, will be called for objects before enqueueing them. Please
	// see the comment on TransformFunc for details.
	Transformer TransformFunc

	// AtomicEvents is used to specify whether the RealFIFO will emit events
	// atomically or not. If it is set, a single event will be emitted
	// atomically for Replace and Resync operations.
	AtomicEvents bool
}

const (
	defaultBatchSize = 1000
)

var _ QueueWithBatch = &RealFIFO{}

// RealFIFO is a Queue in which every notification from the Reflector is passed
// in order to the Queue via Pop.
// This means that it
// 1. delivers notifications for items that have been deleted
// 2. delivers multiple notifications per item instead of simply the most recent value
type RealFIFO struct {
	lock sync.RWMutex
	cond sync.Cond

	items []Delta

	// populated is true if the first batch of items inserted by Replace() has been populated
	// or Delete/Add/Update was called first.
	populated bool
	// initialPopulationCount is the number of items inserted by the first call of Replace()
	initialPopulationCount int


Review comment (suggestion):
suggestion:
```
// ...
// If it is set:
// * a single ReplacedList event will be emitted instead of multiple Replace events
// * a single SyncKnown event will be emitted instead of multiple Sync events
```

Code after:
	"k8s.io/apimachinery/pkg/util/sets"
	utiltrace "k8s.io/utils/trace"
)

// RealFIFOOptions is the configuration parameters for RealFIFO.
type RealFIFOOptions struct {
	// KeyFunction is used to figure out what key an object should have. (It's
	// exposed in the returned RealFIFO's keyOf() method, with additional
	// handling around deleted objects and queue state).
	// Optional, the default is MetaNamespaceKeyFunc.
	KeyFunction KeyFunc

	// KnownObjects is expected to return a list of keys that the consumer of
	// this queue "knows about". It is used to decide which items are missing
	// when Replace() is called; 'Deleted' deltas are produced for the missing items.
	// KnownObjects is required if AtomicEvents is false since it is used to
	// query the state of the internal store for Replace and Resync handling.
	KnownObjects KeyListerGetter

	// If set, will be called for objects before enqueueing them. Please
	// see the comment on TransformFunc for details.
	Transformer TransformFunc

	// AtomicEvents is used to specify whether the RealFIFO will emit events
	// atomically or not. If it is set, a single event will be emitted
	// atomically for Replace and Resync operations.
	// If AtomicEvents is true, KnownObjects must be nil.
	AtomicEvents bool
}

const (
	defaultBatchSize = 1000
)

var _ QueueWithBatch = &RealFIFO{}

// RealFIFO is a Queue in which every notification from the Reflector is passed
// in order to the Queue via Pop.
// This means that it
// 1. delivers notifications for items that have been deleted
// 2. delivers multiple notifications per item instead of simply the most recent value
type RealFIFO struct {
	lock sync.RWMutex
	cond sync.Cond

	items []Delta

	// populated is true if the first batch of items inserted by Replace() has been populated
	// or Delete/Add/Update was called first.
	populated bool
	// initialPopulationCount is the number of items inserted by the first call of Replace()