I need to interop with java code that returns a
CompletableFuture. I want to call the
thenRun method of
CompletableFuture. I am not sure how to do it with clojure.
(.thenRun future ???)
(.thenApply future ???)
In general, how do you deal with functions defined in
java.util.functions in clojure.
You should be able to do that using
reify – see https://github.com/worldsingles/commons/blob/master/src/ws/clojure/extensions.clj#L124-L150 for some syntactic sugar we’ve written around
Clojure function casts fine to the
Function can be declared with
(let [fu (CompletableFuture.)]
(.thenRun fu (fn  (doto :then-run println)))
(.thenApply fu (reify Function
(apply [_ x] (doto :then-apply (println x)))))
(.complete fu :complete))
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.