Howdy,
I'm looking at using Future/Promise to be thread-friendly in some code.
Background... Lift has Futures (or LAFuture... yeah... go ahead make fun of the name... pronounce it with a French accent)... with Lift futures, one can do:
future.foreach(v => /* do something with the value */)
If the Future has been realized (or satisfied in Lift parlance), then the function executes in the current thread. If the Future has not been realized, the function is executed on a thread-pool thread once the Future has been realized. This means that we don't have to consume threads waiting for a Future to finish its work... and we can continue a computation on the thread-pool thread once the future has finished.
Is there a way to get a code block to execute when a Future (or Promise) is realized?
As an adjunct to that question... in Lift, we have fast-fail Futures. You can pass in List[Future[Box[X]]] and get a Future[Box[List[X]]]... but the Box will be Empty if any of the Futures fail (return an Empty Box or a Failure Box). The advantage is that if you fork off a bunch of requests to external systems you can fail-fast with your uber request if any of the systems fail.
Is there a similar facility in Clojure.
Thanks for your time and your help?
David