Re:What's The Point Of Promises?
by dpratt on Thursday March 28, 2013 @10:58AM
(#5455154)
For a more in-depth example of the way that Promises/Futures should work, check out the implementations in Scala or Haskell. The concept of a delayed computation is actually nothing new - the idea has been around for quite some time. I'm actually a little surprised that it's just becoming popular in the Javascript world. From what little experience I've had with reading and writing javascript code, it seems like you are forced by the language into heavy usage of callbacks/continuations. Promises are really the only way to elegantly manage and reason about heavily async code.
[ Parent
| on HN ]
So I wasn't clear what implementation in Haskell you were talking about, since Googling haskell and promise didn't come up with much. I did not realize that "IVars" and "MVars" are considered types of promises until hitting the Wikipedia Futures and Promises page [1]. While I can see how they are promises, that's not how I thought of them.
So if you don't know Haskell but want to see what dpratt is talking about, I'd recommend http://book.realworldhaskell.org/read/concurrent-and-multico... . Someone who knows Scala would have to expand on Scala.
Also note that the .Net AsyncTask is also a promise, and in .Net 4.5 had some powerful syntactic sugar (async/await) that allows you to create sequences of async actions in a very clear way
Re:What's The Point Of Promises?
by douglasisshiny on Thursday March 28, 2013 @12:20PM
(#5455744)
Clojure has agents which work asynchronously, too.
Are you talking about monads?
Not exclusively, since a Future doesn't necessarily have to be monadic to be useful - the Scala version of a Future is (of course) monadic, but you don't necessarily need to know about that to use it.