Skip to content

Instantly share code, notes, and snippets.

@derekwyatt
Created August 7, 2012 19:46
Show Gist options
  • Select an option

  • Save derekwyatt/3288756 to your computer and use it in GitHub Desktop.

Select an option

Save derekwyatt/3288756 to your computer and use it in GitHub Desktop.
Using a Future.sequence() over the Master / Worker remote node pattern
// Downloading could take a while :)
implicit val askTimeout = Timeout(5 minutes)
// Some list of URLs we want to download
val urls = List(url1, ulr2, url3, ..., urlN)
// The Master
val m = system.actorOf(Props[Master], "master")
// Assume Workers are now present
// Get a Future to a bunch of eventual downloaded pages
Future.sequence(urls.map { url =>
m ? Download(url)
}) map { pages =>
PagesReady(pages)
} pipeTo pageRenderer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment