Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created October 8, 2010 11:20
Show Gist options
  • Save kmizu/616638 to your computer and use it in GitHub Desktop.
Save kmizu/616638 to your computer and use it in GitHub Desktop.
import util.continuations._
//scala-arm library http://github.com/jsuereth/scala-arm is needed
import resource._
class SuspendableWrapper[A](t: Iterable[A]) {
def susp = new {
def foreach[B](f: A => B @suspendable): Unit @suspendable = {
val it = t.iterator
while(it.hasNext) {
f(it.next)
}
}
}
}
implicit def toSuspendable[A](t: Iterable[A]) = new SuspendableWrapper(t)
reset {
for(i <- 1 to 10 susp) {
val writer = managed(new java.io.PrintWriter("Hello" + i + ".txt")).!
writer.println("Hello, World " + i + "!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment