Created
April 29, 2012 05:51
-
-
Save conikeec/2533831 to your computer and use it in GitHub Desktop.
Playing with Akka futures
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 java.util.concurrent.Executors | |
import scala.io.Source | |
import akka.dispatch.ExecutionContext | |
import akka.util.duration._ | |
import akka.dispatch.Future | |
implicit val ec = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool()) | |
val words = Source.fromFile("/usr/share/dict/words").getLines | |
// this blows up -- presumably because I'm loading all of words into memory | |
Future.traverse(words.toTraversable)(w => Future { | |
(w.hashCode, w.length) | |
} onSuccess { | |
case (hashCode, length) => println("HASH: %d\tLENGTH: %d".format(hashCode, length)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment