Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
2  
"Future promises producer consumers". (But for programming, swap the last two because Futures (zero or more) is analogous to consumption of a value, and Promise (with only the first one able to succeed) is analogous to producing a value.) –  rwong Aug 4 '13 at 21:28
add comment

4 Answers

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).

share|improve this answer
1  
Related: stackoverflow.com/questions/13381134/… –  rwong Aug 4 '13 at 21:30
add comment

According to wikipedia, they are the same concept:

In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete.

Some libraries may choose to call them one way, some may choose to call them another. And each time, they may be implemented in different flavors. Some libraries may choose to use these synonyms to distinguish different flavors. While I would argue that this is a bad choice (because evidently it confuses people), this link suggests that in Scala this common practice.

As @Ptharien's Flame suggested, in Scala a Future is a read-only operation, while a Promise gives you the ability to yield a result (or failure) for the operation it represents.

A Promise is thus best used by the code responsible to carry out the operation to propagate the result, while a Future is used to expose it to client code, that will in turn await the result. But again, please note that this distinction is Scala specific and may confuse outsiders.

share|improve this answer
add comment

In general these terms are synonyms, but there are many, many libraries in many languages that implement these terms. You will need to read the documentation and/or source for the specific classes in question to understand the difference. But whatever differences you find should not be taken to apply to other Promise or Future libraries - those implementors could flip the design decisions and be just as correct.

share|improve this answer
1  
What does it mean in major usage like Akka, GPars, .Net, Erlang, ML, Haskell, etc. –  Suminda Sirinath Salpitikorala Aug 4 '13 at 18:21
1  
@SumindaSirinathSalpitikorala Have you tried Googling it or reading any documentation? –  djechlin Aug 4 '13 at 19:34
1  
this low effort post would have questionable value even if posted as a comment. "In general these terms are synonyms, but... You will need to read the documentation..." meh do you know How to Answer? –  gnat Aug 5 '13 at 1:49
add comment

As far as I can tell, both promises and futures are the same in theory. In terms of the mentioned libraries, the above also seems to apply.

share|improve this answer
1  
If I use get in a future it blocks. If I do so on a Promise the same happens. Why do I need a Promise? –  Suminda Sirinath Salpitikorala Aug 4 '13 at 16:09
1  
-1 They are not the same in Akka at all. –  Ptharien's Flame Aug 4 '13 at 18:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.