Created
August 22, 2009 17:27
-
-
Save sanity/172879 to your computer and use it in GitHub Desktop.
This file contains 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.continuations._ | |
import scala.continuations.ControlContext._ | |
object ContTest { | |
def get(k : String) = shift { | |
c: (String => Unit) => { | |
if (k == "local") { | |
c("localValue") | |
None | |
} else { | |
Some(c, "remote location") | |
} | |
} | |
} | |
def root() : Option[(String => Unit, String)] = reset { | |
println("Attempting first get"); | |
println("First get result: "+get("remote")); | |
// println("Attempting second get"); | |
// println("Second get result: "+get("remote")); | |
} | |
def main(args: Array[String]) { | |
root() match { | |
case Some((continuation, location)) => { | |
println("We send continuation to "+location+" and execute it"); | |
continuation("Remote Value"); | |
} | |
case None => { | |
println("Root terminated with no continuation"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment