Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created May 2, 2012 20:08
Show Gist options
  • Select an option

  • Save davidandrzej/2579968 to your computer and use it in GitHub Desktop.

Select an option

Save davidandrzej/2579968 to your computer and use it in GitHub Desktop.
ProcessingExample
// record progress every second
val loggingInterval = 1000
var lastLogTime = System.currentTimeMillis()
// count how many elements we've processed
var lastCounter = 0
var counter = 0
elements.foreach { element => {
process(element)
counter += 1
// periodically emit a logging statment
if(System.currentTimeMillis() - lastLogTime > loggingInterval) {
val change = counter - lastCounter
println("Processed %d new items (%d total)".format(change, counter))
lastLogTime = System.currentTimeMillis()
lastCounter = counter
}
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment