Created
April 3, 2012 03:21
-
-
Save raymondtay/2289042 to your computer and use it in GitHub Desktop.
Interactive Input
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
import scala.util.continuations._ | |
object AskMe { | |
def sleep(delay: Long) = shift{ k: (Unit => Int) => | |
val runnable = new Runnable { | |
var leave = false | |
def run = { | |
while( ! leave ) { | |
Thread.sleep(delay) | |
val res = k() | |
res match { | |
case 0 => leave = true | |
case 1 => leave = false | |
} | |
} | |
} | |
} | |
val thread = new Thread(runnable) | |
thread.start | |
} // end of 'shift' | |
def main(args: Array[String]) = { | |
println("Before reset") | |
reset { | |
println("Before sleep") | |
sleep(2000) | |
println("Enter 1 to continue or 0 to exit") | |
val x = readInt | |
x match { | |
case 0 => { println("You've opted to go, well bye bye for now"); 0 } | |
case 1 => { println("You want to go on, well here goes"); 1 } | |
} | |
} // end of 'reset' | |
println("After reset") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment