Created
May 6, 2011 21:19
-
-
Save anonymous/959802 to your computer and use it in GitHub Desktop.
Clojure Future/Promise definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| == 2.4 Futures == | |
| Futures represent asynchronous computations. They are a way to get | |
| code to run in another thread, and obtain the result. | |
| Viktor: Futures represent a (thread-safe) read-handle to a one value that may not yet be present therein | |
| * future : New | |
| * future? : New | |
| * future-done? : New | |
| * future-cancel : New | |
| * future-cancelled? : New | |
| Viktor: The cancel method is problematic since it requires the Future to have two-way-communication, if the Future represent some remote operation, a call to cancel would need to be propagated to the remote endpoint that will populate the value. It also means that the reference to the Future cannot be freely shared as any owner of the handle could cancel the value for all holders of the reference. Also, consider the case where there are 3 or more remotes, where Node1 and Node2 has a Future to Node3 that will provide it with some value, now, a call to cancel on the Future on Node1 would not only need to communicate remotely with Node3, but it would also need to communicate with Node2 so that a call to future-cancelled would yield true on both Node1 and Node2. | |
| While I recognize that Clojure doesn't have remoting, I think the definition is too narrow and does not take into consideration distributed software, where Futures make a whole lot of sense for asynchronous communication. | |
| == 2.5 Promises == | |
| A promise is a synchronization construct that can be used to deliver a | |
| value from one thread to another. Until the value has been delivered, | |
| any attempt to dereference the promise will block. It thus enables | |
| dataflow-style programming. | |
| Viktor: I agree with this in overall, for me a Promise is the write-handle, the flip-side of the Future-coin, and it represents a (thread-safe) write-once field. | |
| * promise : New | |
| * deliver : New |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment