Reputation: 7478
In following code:
val sbtFile: Future[String] = Future{
val f = Source.fromFile("build.sbt")
try f.getLines.mkString("\n") finally f.close()
}
println(s"status: ${sbtFile.isCompleted}")
Thread.sleep(250)
println(s"status: ${sbtFile.isCompleted}")
println(s"value: ${sbtFile.value}")
Future trait has polling method:isCompleted. This method is being called in above code.
In trait Future,this method is:
abstract def isCompleted: Boolean
Also, there is an object,never,defined in Future companion object and it extends Future trait,and returns false for isCompleted.
I couldn't find any other implementation.
So, which concrete completion is being called here?
Upvotes: 0
Views: 369
Reputation: 2938
In IntelliJ, right click on the isCompleted in your code and then Go To > Implementations. One of the places displayed will be scala.concurrent.impl.Promise as @Antot mentioned in the comment:
class DefaultPromise[T] extends AtomicReference[AnyRef](Nil) with Promise[T] {
// ...
override final def isCompleted: Boolean = isCompleted0
// ...
}
Upvotes: 1