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.
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
According to wikipedia, they are the same concept:
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
I'll add a bit here because I have been working with a plethora of Futures in Java as of late but have a background in Scala/Akka development as well. This answer will mostly duplicate what has been said but will point out the plethora of implementations in popular use today on the JVM.
First, original poster mentions using get and blocking - please never ever do this outside of tests.
When I teach FP and Concurrency concepts in my current role, I first tell the student that semantically promises and futures are synonyms because as a consumer of a promise or a future api, the developer does not need to understand that there are or IF there are semantic differences - only the mechanics for handling them without blocking IO.
To say that a future can't be completed and that a promise can (eg as per scala/akka/play apis for example) is too simplistic:
Some Futures can be completed Java8 now introduces a CompletableFuture into the standard library.
Some Promises can't be completed Similarly, in the Play promise API a Promise can't be fulfilled but a RedeemablePromise can so play introduces a different semantic - even while being under the Typesafe umbrella. Further, Play promise API can convert with scala futures in both directions - (F.Promise.wrap(future) or promise.wrapped()).
Working with Typesafe technology on Java8 you will often go back and forth between futures/promises simply because one API is preferable (Play Promise API seems better with Java8 lambdas). On Akka+Play+Java8 you will be taking futures from Actors and wrapping them into promises, composing callbacks, and returning that from the controller.
So, as I tell people when I teach, Promises and Futures are more or less synonyms.
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.
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.
protected by gnat Dec 18 '14 at 16:55
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?