Skip to content

Instantly share code, notes, and snippets.

@sanity
Created August 23, 2009 00:00
Show Gist options
  • Select an option

  • Save sanity/173057 to your computer and use it in GitHub Desktop.

Select an option

Save sanity/173057 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 => Cont) => {
if (k == "local") {
c("localValue")
NoCont()
} else {
IsCont(c, "remote location")
}
}
}
def root() : Cont = reset {
println("Attempting first get");
println("First get result: "+get("remote"));
println("Second get result: "+get("remote"));
}
def main(args: Array[String]) {
execute(root())
}
def execute(cont : Cont) {
println("Execute("+cont+")")
cont match {
case IsCont(contFunc, location) => {
println("Continuation moved to "+location+", executing")
execute(contFunc("remote value"));
}
case NoCont() => {
println("No more continuations to execute")
}
}
}
}
abstract class Cont
case class NoCont() extends Cont
case class IsCont(contFunc : (String => Cont), location : String) extends Cont
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment