Skip to content

Instantly share code, notes, and snippets.

@songpp
Created April 2, 2011 08:01
Show Gist options
  • Save songpp/899323 to your computer and use it in GitHub Desktop.
Save songpp/899323 to your computer and use it in GitHub Desktop.
scala delimited continuations
package flower.april.continuation
import scala.util.continuations._
import java.util.{Timer, TimerTask}
/**
* User: i-flower
* Date: 2010-8-10
* Time: 20:28:05
* this blow up my mind
*/
object Cc {
def unknown = {
val timer = new Timer()
def sleep(delay: Int) = shift {
k: (Unit => Unit) =>
timer.schedule(new TimerTask {
def run() = k() // in a real program, we'd execute k on a thread pool
}, delay)
}
println("look, Ma ...")
reset {sleep(1000)}
println(" no threads!")
}
def inMyMind = {
() => reset{
println(1)
shift{
cont : (Unit => Unit) =>
cont()
println(2)
}
println(3)
}
}
inMyMind
def main(ar: Array[String]): Unit = {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment