Skip to content

Commit

Permalink
refine first page flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT committed Feb 9, 2022
1 parent 55d1a8c commit 4110ad5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sdk/azcore/runtime/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ type PageProcessor[T any] struct {
type Pager[T any] struct {
current T
handler PageProcessor[T]
lroSecond bool
firstPage bool
}

// NewPager creates an instance of Pager using the specified PageProcessor.
func NewPager[T any](pageHandler PageProcessor[T]) *Pager[T] {
return &Pager[T]{
handler: pageHandler,
handler: pageHandler,
firstPage: true,
}
}

Expand All @@ -61,18 +62,18 @@ func (p *Pager[T]) More() bool {
func (p *Pager[T]) NextPage(ctx context.Context) (T, error) {
var req *policy.Request
var err error
if !reflect.ValueOf(p.current).IsZero() && !p.lroSecond {
if !reflect.ValueOf(p.current).IsZero() && p.firstPage {
// we get here if it's an LRO-pager, we already have the first page
p.lroSecond = true
p.firstPage = false
return p.current, nil
} else if !reflect.ValueOf(p.current).IsZero() {
if !p.handler.More(p.current) {
return *new(T), errors.New("no more pages")
}
req, err = p.handler.Advancer(ctx, p.current)
} else {
// non-LRO case, so skip the LRO branch above
p.lroSecond = true
// non-LRO case
p.firstPage = false
req, err = p.handler.Requester(ctx)
}
if err != nil {
Expand Down

0 comments on commit 4110ad5

Please sign in to comment.