Skip to content

Commit 8a107b6

Browse files
committed
Replace ResultsWithProcess with ResultsWithContext
1 parent d052982 commit 8a107b6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

query/query.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ func NewResultBuilder(q Query) *ResultBuilder {
243243
// DEPRECATED: This iterator is impossible to cancel correctly. Canceling it
244244
// will leave anything trying to write to the result channel hanging.
245245
func ResultsWithChan(q Query, res <-chan Result) Results {
246-
proc := func(ctx context.Context, cancel context.CancelFunc, out chan<- Result) {
247-
defer cancel()
246+
return ResultsWithContext(q, func(ctx context.Context, out chan<- Result) {
248247
for {
249248
select {
250249
case <-ctx.Done(): // client told us to close early
@@ -261,12 +260,18 @@ func ResultsWithChan(q Query, res <-chan Result) Results {
261260
}
262261
}
263262
}
264-
}
263+
})
264+
}
265265

266+
// ResultsWithCtxs returns a Results object with the results generated by the
267+
// passed proc function called in a separate goroutine.
268+
func ResultsWithContext(q Query, proc func(context.Context, chan<- Result)) Results {
266269
b := NewResultBuilder(q)
267270

268-
// go consume all the entries and add them to the results.
269-
go proc(b.ctx, b.cancel, b.Output)
271+
go func() {
272+
defer b.cancel()
273+
proc(b.ctx, b.Output)
274+
}()
270275

271276
return b.Results()
272277
}

0 commit comments

Comments
 (0)