cloroutine
cloroutine copied to clipboard
reflection errors for this code example:
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