0

When I create an ad-hoc future and call it it works ok.

scala> val f = future {Thread.sleep(1000 * 60 * 1); println("Hi"); 20}
f: scala.actors.Future[Int] = 

scala> f()
Hi
res39: Int = 20

When I create the same future and call awaitAll it does not work. The awaitAll returns None as if the future were not resolved.

scala> val f = future {Thread.sleep(1000 * 60 * 1); println("Hi"); 20}
f: scala.actors.Future[Int] = 

scala> awaitAll(1000 * 60 * 2, f)
Hi
res40: List[Option[Any]] = List(None)
Michael
  • 10,185
  • 12
  • 59
  • 110

2 Answers2

1

Prefer the future over Future which is deprecated.

How about: "Prefer the Future of the future in scala.concurrent to the Future of the past in scala.actors, which is deprecated."

As usual, Heather Miller says it best; see comment.

object Test extends App {
  import scala.concurrent._
  import Await._
  import Future._
  import duration._
  import ExecutionContext.Implicits.global

  val data = List(1,2,3)
  result(traverse(data)(i => future{10 * i}), Duration("10 sec")) foreach println
}
som-snytt
  • 39,429
  • 2
  • 47
  • 129
1

I hope to help you.

import scala.actors._

object StackOverFlow13331294 extends App {
    Futures awaitAll (1000 * 60 * 1,
            Seq(new StackOverFlow13331294 !! "execute"): _*) foreach println
}

class StackOverFlow13331294 extends Actor {
    start
    override def act = react {
        case "execute" =>
            // Thread sleep 1000 * 60 * 1 ?
            println("Hi")
            reply("20")
    }
}
J Camphor
  • 303
  • 1
  • 7