eachListChunkBuffered fetches runtimeObject list chunks using this ListPager and invokes fn on each list chunk. If fn returns an error, processing stops and that error is returned. If fn does not return an error, any error encountered while retrieving the list from the server is returned. If the co
(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error)
| 152 | // |
| 153 | // Up to ListPager.PageBufferSize chunks are buffered concurrently in the background. |
| 154 | func (p *ListPager) eachListChunkBuffered(ctx context.Context, options metav1.ListOptions, fn func(obj runtime.Object) error) error { |
| 155 | if p.PageBufferSize < 0 { |
| 156 | return fmt.Errorf("ListPager.PageBufferSize must be >= 0, got %d", p.PageBufferSize) |
| 157 | } |
| 158 | |
| 159 | // Ensure background goroutine is stopped if this call exits before all list items are |
| 160 | // processed. Cancelation error from this deferred cancel call is never returned to caller; |
| 161 | // either the list result has already been sent to bgResultC or the fn error is returned and |
| 162 | // the cancelation error is discarded. |
| 163 | ctx, cancel := context.WithCancel(ctx) |
| 164 | defer cancel() |
| 165 | |
| 166 | chunkC := make(chan runtime.Object, p.PageBufferSize) |
| 167 | bgResultC := make(chan error, 1) |
| 168 | go func() { |
| 169 | defer utilruntime.HandleCrash() |
| 170 | |
| 171 | var err error |
| 172 | defer func() { |
| 173 | close(chunkC) |
| 174 | bgResultC <- err |
| 175 | }() |
| 176 | err = p.eachListChunk(ctx, options, func(chunk runtime.Object) error { |
| 177 | select { |
| 178 | case chunkC <- chunk: // buffer the chunk, this can block |
| 179 | case <-ctx.Done(): |
| 180 | return ctx.Err() |
| 181 | } |
| 182 | return nil |
| 183 | }) |
| 184 | }() |
| 185 | |
| 186 | for o := range chunkC { |
| 187 | err := fn(o) |
| 188 | if err != nil { |
| 189 | return err // any fn error should be returned immediately |
| 190 | } |
| 191 | } |
| 192 | // promote the results of our background goroutine to the foreground |
| 193 | return <-bgResultC |
| 194 | } |
| 195 | |
| 196 | // eachListChunk fetches runtimeObject list chunks using this ListPager and invokes fn on each list |
| 197 | // chunk. If fn returns an error, processing stops and that error is returned. If fn does not return |