Skip to content

Commit b12933d

Browse files
committed
Simplify Vals
1 parent 05cc02a commit b12933d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

iterator.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,35 @@ func (it *ScanIterator) Val() string {
7373
// Vals returns iterator over key/field at the current cursor position.
7474
func (it *ScanIterator) Vals(ctx context.Context) iter.Seq[string] {
7575
return func(yield func(string) bool) {
76-
for it.Next(ctx) {
77-
if !yield(it.Val()) {
76+
if it.cmd.Err() != nil {
77+
return
78+
}
79+
80+
for {
81+
for _, val := range it.cmd.page {
82+
if !yield(val) {
83+
return
84+
}
85+
}
86+
87+
// Return if there is no more data to fetch.
88+
if it.cmd.cursor == 0 {
89+
return
90+
}
91+
92+
// Fetch next page.
93+
var cursorIndex int
94+
switch it.cmd.args[0] {
95+
case "scan", "qscan":
96+
cursorIndex = 1
97+
default:
98+
cursorIndex = 2
99+
}
100+
101+
it.cmd.args[cursorIndex] = it.cmd.cursor
102+
103+
err := it.cmd.process(ctx, it.cmd)
104+
if err != nil {
78105
return
79106
}
80107
}

0 commit comments

Comments
 (0)