Skip to content

Instantly share code, notes, and snippets.

@schmmd
Last active August 29, 2015 14:08
Show Gist options
  • Save schmmd/d0d791b6a9f38e695537 to your computer and use it in GitHub Desktop.
Save schmmd/d0d791b6a9f38e695537 to your computer and use it in GitHub Desktop.
def all[T : RootJsonFormat](esDocConf: ESDocConf, batchSize: Int = 100): Iterator[T] =
new Iterator[T] {
var i = 0
private def read() = {
val items = read(esDocConf, i * batchSize, batchSize)
i = i + 1
items
}
private var batch = read()
override def hasNext: Boolean = {
if (batch.isEmpty) {
batch = read
}
!batch.isEmpty
}
override def next: T = {
if (batch.isEmpty) {
batch = read
}
val top = batch.head
batch = batch.tail
top
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment