fork download
  1. object TimerExample {
  2. /** Runs the passed in function pausing approxmimately one second in between calls.
  3.   * as long as the function returns true.
  4.   */
  5. def oncePerSecond(callback: () => Boolean) {
  6. while(callback()) {
  7. Thread sleep 1000
  8. }
  9. }
  10.  
  11. /** Counts down from 0 to 1, approxmimately once per second.
  12.   */
  13. def main(args: Array[String]) {
  14. var count = 10
  15. oncePerSecond(() => {println(count); count -= 1; count > 0})
  16. }
  17. }
  18.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty