func()

in readers/apiserver/watchlist/internal/watchlist/watchlist.go [515:542]


func (r *Reader) watchEvents(ctx context.Context, watcher watch.Interface) (string, error) {
	if r.fakeWatchEvents != nil {
		return r.fakeWatchEvents(ctx, watcher)
	}

	ch := watcher.ResultChan()

	var resourceVersion string

	stopper := sync.OnceFunc(
		func() {
			watcher.Stop()
		},
	)

	for {
		rv, err := r.watchEvent(ctx, ch, stopper)
		if rv != "" {
			resourceVersion = rv
		}
		// Always an io.EOF, so we don't log it, we just exit.
		if err != nil {
			break
		}
	}

	return resourceVersion, nil
}