Created
May 2, 2012 20:08
-
-
Save davidandrzej/2579968 to your computer and use it in GitHub Desktop.
ProcessingExample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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