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")
}
Source: stackoverflow.com
Related Query
- Scala Future - beginner query
- Beginner Scala SBT query
- How to return Future of Either[Throwable,Int] from a Scala Slick Query output
- Future investment: Erlang vs. Scala
- Is Future in Scala a monad?
- Nashorn and Scala future to JS Promise conversion
- ListenableFuture to scala Future
- Scala slick query where in list
- Convert a Java Future to a Scala Future
- Scala Future with filter in for comprehension
- Future with Timeout in Scala
- Get rid of Scala Future nesting
- Error handling Scala : Future For Comprehension
- What are the differences between a Scala Future and a Java Future
- Scala - URL with Query String Parser and Builder DSL
- What are advantages of a Twitter Future over a Scala Future?
- Convert scala future to java future
- scala slick query return value
- Convert scala 2.10 future to scalaz.concurrent.Future // Task
- MongoDB scala driver: what is a best way to return Future when working with Observer callbacks?
- Converting Scala @suspendable Method into a Future
- Cancellation with Future and Promise in Scala
- Scala slick query comparison of a custom user type (enumeration) gives error
- Scala Future mapTo fails to compile because of missing ClassTag
- convert Scala Future to Twitter Future
- Scala for comprehension with future and options
- Kill or timeout a Future in Scala 2.10
- Scala future sequence and timeout handling
- Does a wait on Scala Future block thread?
- Convert query string to map in scala
More Query from same tag
- Use infiniband with Akka in Scala?
- Decoding a sealed trait in Argonaut based on JSON structure?
- Scala - No TypeTag Available Exception when using case class to try to get TypeTag?
- Creating a Dataframe using spark2-shell and got this error
- Scala: Use implicits in companion object
- 3? ways in scala to return a function from a function - 1 doesn't compile - don't understand why
- Creating extension methods for SeqLike
- How to disable Scala warning "The outer reference in this type test cannot be checked at run time"
- Gradle: java.lang.StackOverflowError when compiling a spark-scala program
- SBT plugin just for your local machine
- Find columns with different values
- Why does 'toSet' method mix up ordering of elements in ListBuffer?
- Spark fails to read from Elasticsearch/Opensearch. Invalid map received dynamic_date_formats
- Spark Scala - Split columns into multiple rows
- For comprehension with optional collection iteration and yield
- spark scala scala.MatchError of class scala.collection.immutable.$colon$colon
- construct case class from collection of parameters
- Split RDD into RDD's with no repeating values
- what is the map/flatmap function used in for comprehensions?
- playframework : i18n + scala
- Akka synchronizing timestamped messages from several actors
- Why doesn't a prism set function return an Option/Maybe
- Two URLClassLoaders with the same classpath with different behaviour
- How to pass remote references between Akka actors?
- How does sbt integrate with IntelliJ?
- Spark streaming for Kafka: How to get the topic name from Kafka consumer DStream?
- Bit Manipulation for DNA file Convert
- Promote Class to Manifest?
- Is it possible to specify function as parameter's default value?
- Is is possible to reference function's parameter in the documention text?