Is there a way to set a watch on a future so that it triggers a callback when it is done?
something like this?
> (def a (future (Thread/sleep 1000) \"
For very simple cases: If you dont want to block and dont care about the result just add the callback in the future definition.
(future (a-taking-time-computation) (the-callback))
If you care about the result use comp with the call back
(future (the-callback (a-taking-time-computation)))
or
(future (-> input a-taking-time-computation callback))
Semantically speaking the java equivalent code would be:
final MyCallBack callbackObj = new MyCallBack();
new Thread() {
public void run() {
a-taking-time-computation();
callbackObj.call();
}
}.start()
For complex cases you may want to look:
https://github.com/ztellman/manifold
https://github.com/clojure/core.async