The difference between a Future and a Promise

akkaapigroovyscala

What is the difference between a Future and a promise? (In Akka and Gpars.)

They look the same to me as both block and return the value of the future when get is called and a promise is to get the result of a future.

Best Answer

I'll talk about Akka/Scala, because I'm not familiar with Gpars nor with Akka/Java.

In Scala 2.10, which includes the relevant part of Akka in the standard distribution, a Future is essentially a read-only reference to a yet-to-be-computed value. A Promise is a pretty much the same except that you can write to it as well. In other words, you can read from both Futures and Promises, but you can only write to Promises. You can get the Future associated with a Promise by calling the future method on it, but conversion in the other direction is not possible (because it would be nonsensical).