Is there a way to directly get the value out of a successful promise?
Is it really necessary to connect a future
to the promise, for that?
scala> import scala.concurrent._
import scala.concurrent._
scala> val result = Promise[Int]
result: scala.concurrent.Promise[Int] = scala.concurrent.impl.Promise$DefaultPromise@2b5fa85f
scala> result success 3
res0: result.type = scala.concurrent.impl.Promise$DefaultPromise@2b5fa85f
scala> result
res1: scala.concurrent.Promise[Int] = scala.concurrent.impl.Promise$DefaultPromise@2b5fa85f
scala> result.isCompleted
res4: Boolean = true
scala> result.value
<console>:12: error: value value is not a member of scala.concurrent.Promise[Int]
result.value
^
scala> result.future.value.get.get
res6: Int = 3
I am considering using a promise for thread-safe "assign once" semantics. The promise object looks lean enough in the scala.concurrent source, and as far as I understand it is thread safe. I'd rather however, avoid adding another object (a future). I could not find a getter for the success value of a promise.