Created
August 23, 2009 00:00
-
-
Save sanity/173057 to your computer and use it in GitHub Desktop.
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.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