Tuesday, September 4, 2012

[Clojure] Difference between future and promise

The difference between future and promise can be quite confusing. Heck, even I am confused. So I went and asked at #clojure @freenode

<firesofmay> Can anyone tell me why is Promise called as "Promise"? What is the context? I understand (a bit) what they do. But I am trying to understand the reason to name it that way.

<weavejester> firesofmay: You're promising to assign it a value at a later date.
 

<firesofmay> weavejester, ah okay. and future is like, this function call will return its value sometime in future. Am I correct?
 

<gfredericks> a future is like a promise where you give it the computation to produce the result at the same time you create the future itself
 

<weavejester> firesofmay: Yes… but more precisely, what gfredericks said :)
 

<gfredericks> promises decouple that; you create a promise without saying anything about who computes its value or how
 

<weavejester> A future is essentially a promise + a calculation in a background thread that fulfills the promise.
 

<firesofmay> gfredericks, ah that clears the difference.
 

<firesofmay> weavejester, now I got it :)

Hope that helps someone :)

Thanks to  gfredericks & weavejester.

Reference Links :
1) How do Clojure futures and promises differ?

2) Episode 1 - Futures & Promises

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.