Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove ResultBuilder
  • Loading branch information
gammazero committed Feb 26, 2025
commit 0dbca94435fd67a857f3533b328871dc7518ce17
52 changes: 0 additions & 52 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package query
import (
"context"
"fmt"
"sync"
"time"
)

Expand Down Expand Up @@ -201,57 +200,6 @@ func (r *results) Done() <-chan struct{} {
return r.closed
}

// ResultBuilder is what implementors use to construct results
// Implementors of datastores and their clients must respect the
// Process of the Request:
//
// - clients must call r.Process().Close() on an early exit, so
// implementations can reclaim resources.
// - if the Entries are read to completion (channel closed), Process
// should be closed automatically.
// - datastores must respect <-Process.Closing(), which intermediates
// an early close signal from the client.
type ResultBuilder struct {
Query Query
Output chan Result

ctx context.Context
cancel context.CancelFunc
closed chan struct{}
wg sync.WaitGroup
}

// Results returns a Results to to this builder.
func (rb *ResultBuilder) Results() Results {
return &results{
query: rb.Query,
res: rb.Output,

cancel: rb.cancel,
closed: rb.closed,
}
}

func NewResultBuilder(q Query) *ResultBuilder {
bufSize := NormalBufSize
if q.KeysOnly {
bufSize = KeysOnlyBufSize
}
b := &ResultBuilder{
Query: q,
Output: make(chan Result, bufSize),
closed: make(chan struct{}),
}

b.ctx, b.cancel = context.WithCancel(context.Background())
context.AfterFunc(b.ctx, func() {
b.wg.Wait()
close(b.Output)
close(b.closed)
})
return b
}

// ResultsWithContext returns a Results object with the results generated by
// the passed proc function called in a separate goroutine.
func ResultsWithContext(q Query, proc func(context.Context, chan<- Result)) Results {
Expand Down