1

Possible Duplicate:
What is the Scala equivalent of F#'s async workflows?

Is there an equivalent to F# async workflows in Scala ? I would like to use this to crawl webpages concurrently.

Thank you

Community
  • 1
  • 1
jlezard
  • 1,417
  • 2
  • 15
  • 32

1 Answers1

2

To execute a task asynchronously in parallel, simply use Actor.actor method:

import scala.actors.Actor._

actor {
  // code here is excuted asynchronously  
}

To execute a task and wait for a result, use futures:

import scala.actors.Futures.future

val f = future {
  // code here is excuted asynchronously
  // last expression is returned
}
//... other code
val result = f() // block until f is completed and return the value

For more complex workflows, have a look at Scala (or Akka) actors. You can also have a look at java NIO which allows async IO operations.

paradigmatic
  • 40,153
  • 18
  • 88
  • 147