Skip to content
Browse files

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

  • Loading branch information...
1 parent 0c0b519 commit 2817def6425bb978ce503b7040f86fdb012e5c0b @ztellman committed Apr 30, 2012
Showing with 25 additions and 1 deletion.
  1. +25 −1 src/lamina/core/result.clj
View
26 src/lamina/core/result.clj
@@ -205,7 +205,31 @@
(recur)))
result#)))))))
-(deftype-once ResultChannel
+(defmacro def-result-channel [params & body]
+ (let [{:keys [major minor]} *clojure-version*]
+ `(deftype-once ~'ResultChannel
+ ~params
+ ~@(when-not (and (= 1 major) (= 2 minor))
+ `(
+ clojure.lang.IPending
+ (isRealized [this#] (boolean (result this#)))
+
+ clojure.lang.IBlockingDeref
+ (deref [this# timeout-ms# timeout-val#]
+ (let [r# (result-channel)]
+ (t/delay-invoke r# timeout-ms# #(success r# timeout-val#))
+ (subscribe this#
+ (result-callback
+ #(success r# %)
+ #(error r# %)))
+ @r#))))
+ ~@body)))
+
+(declare
+ result-channel
+ result-callback)
+
+(def-result-channel
[^Lock lock
^{:volatile-mutable true :tag ResultState} state
^LinkedList subscribers]

0 comments on commit 2817def

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