4 ms·
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 computatio
by dpratt 14y ago
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.
- jiggy2011 14y agoAre you talking about monads?
- dpratt 14y agoNot 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.
- jerf 14y agoSo 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-multicore-programming.html http://book.realworldhaskell.org/read/concurrent-and-multico... . Someone who knows Scala would have to expand on Scala. [1]: http://en.wikipedia.org/wiki/Futures_and_promises http://en.wikipedia.org/wiki/Futures_and_promises
- pacaro 14y agoAlso 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
- douglasisshiny 14y agoClojure has agents which work asynchronously, too.