atline atline - 1 month ago 15
Scala Question

What's the difference for Future and future?

Next code are both Ok, why we need the new function future? It seems future just has following signture, anything I miss E.g. for some situation we can just use one of them?

def future[T](body: =>T)(implicit execctx: ExecutionContext): Future[T] = Future[T](body)


Following is the test code:

import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global

Future {
println("1")
}

future {
println("2")
}

Thread.sleep(3)

Answer

scala.concurrent.future was deprecated in 2.11.0 and will be removed in a future version of Scala, so the answer is you don't need both, and don't use future.

Comments