Skip to content

Instantly share code, notes, and snippets.

@sanity
Created August 22, 2009 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanity/172879 to your computer and use it in GitHub Desktop.
Save sanity/172879 to your computer and use it in GitHub Desktop.
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