Skip to content
This repository
Browse code

implement clojure.lang.IPending when running in >= 1.3, fixes #35

  • Loading branch information...
commit 2817def6425bb978ce503b7040f86fdb012e5c0b 1 parent 0c0b519
Zach Tellman authored

Showing 1 changed file with 25 additions and 1 deletion. Show diff stats Hide diff stats

  1. +25 1 src/lamina/core/result.clj
26 src/lamina/core/result.clj
@@ -205,7 +205,31 @@
205 205 (recur)))
206 206 result#)))))))
207 207
208   -(deftype-once ResultChannel
  208 +(defmacro def-result-channel [params & body]
  209 + (let [{:keys [major minor]} *clojure-version*]
  210 + `(deftype-once ~'ResultChannel
  211 + ~params
  212 + ~@(when-not (and (= 1 major) (= 2 minor))
  213 + `(
  214 + clojure.lang.IPending
  215 + (isRealized [this#] (boolean (result this#)))
  216 +
  217 + clojure.lang.IBlockingDeref
  218 + (deref [this# timeout-ms# timeout-val#]
  219 + (let [r# (result-channel)]
  220 + (t/delay-invoke r# timeout-ms# #(success r# timeout-val#))
  221 + (subscribe this#
  222 + (result-callback
  223 + #(success r# %)
  224 + #(error r# %)))
  225 + @r#))))
  226 + ~@body)))
  227 +
  228 +(declare
  229 + result-channel
  230 + result-callback)
  231 +
  232 +(def-result-channel
209 233 [^Lock lock
210 234 ^{:volatile-mutable true :tag ResultState} state
211 235 ^LinkedList subscribers]

0 comments on commit 2817def

Please sign in to comment.
Something went wrong with that request. Please try again.