cloroutine icon indicating copy to clipboard operation
cloroutine copied to clipboard

reflection errors for this code example:

Open zcaudate opened this issue 4 years ago • 0 comments

Given the code example, this gives a warning:

(require '[cloroutine.core :refer [cr]])
(import '(java.util.concurrent CompletableFuture))

(def ^:dynamic *fiber*)
(def ^:dynamic *value*)
(def ^:dynamic *error*)
(defn await [cf] (.whenComplete ^CompletableFuture cf *fiber*))
(defn thunk [] (if-some [e *error*] (throw e) *value*))

(defmacro async [& body]
  `(let [cf# (CompletableFuture.)
         cr# (cr {await thunk}
               (try (.complete cf# (do ~@body))
                    (catch Throwable e#
                      (.completeExceptionally cf# e#))))]
     (binding [*fiber* (reify java.util.function.BiConsumer
                         (accept [f# v# e#]
                           (binding [*fiber* f#
                                     *value* v#
                                     *error* e#]
                             (cr#))))]
       (cr#)) cf#))


;;; turn on reflections
(set! *warn-on-reflection* true)

;;; example
(async (await (async 1))
;;;       |
;;;       ^ reflection warning

zcaudate avatar Aug 17 '20 15:08 zcaudate