Created
April 2, 2011 08:01
-
-
Save songpp/899323 to your computer and use it in GitHub Desktop.
scala delimited continuations
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
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