Skip to content

Instantly share code, notes, and snippets.

@Aankhen
Forked from raymondtay/gist:2289042
Created April 9, 2012 15:31
Show Gist options
  • Save Aankhen/2344262 to your computer and use it in GitHub Desktop.
Save Aankhen/2344262 to your computer and use it in GitHub Desktop.
Interactive Input
import scala.util.continuations._
// might need to be compiled and run separately due to a bug in App
object ContinuationsExample extends App {
def prompt(display: String): Boolean = {
print(display + " (Y/N) ")
Console.readLine.trim.headOption match {
case Some('Y') | Some('y') => true
case Some('N') | Some('n') => false
case _ => prompt(display)
}
}
def delay(duration: Long) =
shift {
k: (Unit => Boolean) =>
do {
println("%nSleeping for %d milliseconds..." format (duration))
Thread.sleep(duration)
} while (k())
}
println("Before reset")
reset {
delay(2000)
prompt("Repeat?")
}
println("\nAfter reset")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment