File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -243,8 +243,7 @@ func NewResultBuilder(q Query) *ResultBuilder {
243
243
// DEPRECATED: This iterator is impossible to cancel correctly. Canceling it
244
244
// will leave anything trying to write to the result channel hanging.
245
245
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 ) {
248
247
for {
249
248
select {
250
249
case <- ctx .Done (): // client told us to close early
@@ -261,12 +260,18 @@ func ResultsWithChan(q Query, res <-chan Result) Results {
261
260
}
262
261
}
263
262
}
264
- }
263
+ })
264
+ }
265
265
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 {
266
269
b := NewResultBuilder (q )
267
270
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
+ }()
270
275
271
276
return b .Results ()
272
277
}
You can’t perform that action at this time.
0 commit comments