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 {
243243// DEPRECATED: This iterator is impossible to cancel correctly. Canceling it
244244// will leave anything trying to write to the result channel hanging.
245245func 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}
You can’t perform that action at this time.
0 commit comments