Skip to content

Commit

Permalink
Avoid creating extra goroutines on nextIter (apache#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima authored Oct 24, 2020
1 parent 393f0c9 commit 5913df4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ Pavel Buchinchik <p.buchinchik@gmail.com>
Rintaro Okamura <rintaro.okamura@gmail.com>
Yura Sokolov <y.sokolov@joom.com>; <funny.falcon@gmail.com>
Jorge Bay <jorgebg@apache.org>
Dmitriy Kozlov <hummerd@mail.ru>
17 changes: 12 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ func (iter *Iter) Scan(dest ...interface{}) bool {
}

if iter.next != nil && iter.pos >= iter.next.pos {
go iter.next.fetch()
iter.next.fetchAsync()
}

// currently only support scanning into an expand tuple, such that its the same
Expand Down Expand Up @@ -1526,10 +1526,17 @@ func (iter *Iter) NumRows() int {
}

type nextIter struct {
qry *Query
pos int
once sync.Once
next *Iter
qry *Query
pos int
oncea sync.Once
once sync.Once
next *Iter
}

func (n *nextIter) fetchAsync() {
n.oncea.Do(func() {
go n.fetch()
})
}

func (n *nextIter) fetch() *Iter {
Expand Down

0 comments on commit 5913df4

Please sign in to comment.