score:1

Accepted answer

@thilo is right, your app is exited faster than future starts executing. basically, using await.result is not good practice when you work with future, so this example only for education purpose :)

import scala.concurrent.{await, executioncontext, future}
import scala.concurrent.duration._

object usefuture extends app
{
  implicit val ec = executioncontext.global
  println(s"current thread: ${thread.currentthread().getid}")
  val future = future(println { s"thread id in future: ${thread.currentthread().getid}. this should be run in another thread" })

  await.result(future, 15.seconds)
  println("future has been executed")
}

More Query from same tag