Skip to content

Instantly share code, notes, and snippets.

@eranharel
Last active January 16, 2018 15:00
Show Gist options
  • Save eranharel/8aa533418bae84af20dcd6e310bb1212 to your computer and use it in GitHub Desktop.
Save eranharel/8aa533418bae84af20dcd6e310bb1212 to your computer and use it in GitHub Desktop.
(defn listenablefuture-handler
[lf on-success-func on-fail-func]
(Futures/addCallback
lf
(reify FutureCallback
(onSuccess [_ res]
(on-success-func res))
(onFailure [_ e]
(on-fail-func e))))
lf)
(listenablefuture-handler (Futures/immediateFuture "666")
(fn [res] (println "Got results: " res))
(fn [e] (println "Got error: " e)))
(listenablefuture-handler (Futures/immediateFailedFuture (new java.lang.RuntimeException))
(fn [res] (println "Got results: " res))
(fn [e] (println "Got error: " e)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment