|
@@ -72,6 +72,7 @@ func NewPager[T any](
|
|
done := make(chan struct{})
|
|
done := make(chan struct{})
|
|
|
|
|
|
return &pager[T]{
|
|
return &pager[T]{
|
|
|
|
+ pctx: ctx,
|
|
ctx: ctx2,
|
|
ctx: ctx2,
|
|
cancel: cancel,
|
|
cancel: cancel,
|
|
done: done,
|
|
done: done,
|
|
@@ -87,6 +88,7 @@ Retrieve n items in the range [m*n, m*n + n - 1], inclusive.
|
|
We keep len(pagePool) pages buffered.
|
|
We keep len(pagePool) pages buffered.
|
|
*/
|
|
*/
|
|
type pager[T any] struct {
|
|
type pager[T any] struct {
|
|
|
|
+ pctx context.Context // Parent context.
|
|
ctx context.Context
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
cancel context.CancelFunc
|
|
done chan struct{} // Notify Abort when finished.
|
|
done chan struct{} // Notify Abort when finished.
|
|
@@ -177,8 +179,17 @@ func (p *pager[T]) LastErr() error {
|
|
return p.err
|
|
return p.err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (p *pager[T]) reset() error {
|
|
|
|
+ err := p.err
|
|
|
|
+ p.ctx, p.cancel = context.WithCancel(p.pctx)
|
|
|
|
+ p.done = make(chan struct{})
|
|
|
|
+ p.m, p.cnt = 0, 0
|
|
|
|
+ p.err = nil
|
|
|
|
+ return err
|
|
|
|
+}
|
|
|
|
+
|
|
func (p *pager[T]) Abort() error {
|
|
func (p *pager[T]) Abort() error {
|
|
p.cancel()
|
|
p.cancel()
|
|
<-p.done
|
|
<-p.done
|
|
- return nil
|
|
|
|
|
|
+ return p.reset()
|
|
}
|
|
}
|