Created
October 8, 2010 11:20
-
-
Save kmizu/616638 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 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