Skip to content

Commit 612f26b

Browse files
committed
kgo: add Fetches.RecordsAll to return a Go native iterator
1 parent 29dc44e commit 612f26b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎pkg/kgo/group_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ func (c *testConsumer) etl(etlsBeforeQuit int) {
202202
}
203203
netls++
204204

205-
for iter := fetches.RecordIter(); !iter.Done(); {
206-
r := iter.Next()
205+
for r := range fetches.RecordsAll() {
207206
keyNum, err := strconv.Atoi(string(r.Key))
208207
if err != nil {
209208
c.errCh <- err

‎pkg/kgo/record_and_fetch.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kgo
33
import (
44
"context"
55
"errors"
6+
"iter"
67
"reflect"
78
"time"
89
"unsafe"
@@ -521,6 +522,19 @@ beforePartition:
521522
}
522523
}
523524

525+
// RecordsAll returns a Go native iterator that yields the records in a fetch.
526+
//
527+
// Similarly to RecordIter(), the errors should be inspected separately.
528+
func (fs Fetches) RecordsAll() iter.Seq[*Record] {
529+
return func(yield func(*Record) bool) {
530+
for iter := fs.RecordIter(); !iter.Done(); {
531+
if !yield(iter.Next()) {
532+
return
533+
}
534+
}
535+
}
536+
}
537+
524538
// EachPartition calls fn for each partition in Fetches.
525539
//
526540
// Partitions are not visited in any specific order, and a topic may be visited

0 commit comments

Comments
 (0)