Skip to content

Instantly share code, notes, and snippets.

@conikeec
Created April 29, 2012 05:51
Show Gist options
  • Save conikeec/2533831 to your computer and use it in GitHub Desktop.
Save conikeec/2533831 to your computer and use it in GitHub Desktop.
Playing with Akka futures
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