Permalink
Browse files

add support for callback & subscribe

  • Loading branch information...
1 parent 0fdb4d5 commit e662c855bff8b645b02146a3fb0d0750f7bddf9b @jaycfields committed Mar 23, 2012
Showing with 30 additions and 7 deletions.
  1. +3 −2 project.clj
  2. +10 −1 src/clojure/jreg/core.clj
  3. +0 −4 test/jreg/expectations/core.clj
  4. +17 −0 test/jreg/expectations/core_expectations.clj
View
@@ -1,7 +1,8 @@
-(defproject jry "1.0.6"
+(defproject jreg "0.0.1"
:description "general clojure functions"
:jar-name "jreg.jar"
:dependencies [[org.clojure/clojure "1.3.0"]]
:dev-dependencies [[expectations "1.3.5"]
[lein-expectations "0.0.1"]
- [lein-publishers "1.0.4"]])
+ [lein-publishers "1.0.4"]
+ [org.jetlang/jetlang "0.2.9"]])
View
@@ -1 +1,10 @@
-(ns jreg.core)
+(ns jreg.core
+ (:import [org.jetlang.core Callback]))
+
+(defn ->callback [f]
+ (reify Callback
+ (onMessage [_ message]
+ (f message))))
+
+(defn subscribe [channel executor f]
+ (.subscribe channel executor (->callback f)))
@@ -1,4 +0,0 @@
-(ns jreg.expectations.core
- (:use expectations jreg.core))
-
-(expect nil? nil)
@@ -0,0 +1,17 @@
+(ns jreg.expectations.core-expectations
+ (:import [org.jetlang.core Callback SynchronousDisposingExecutor]
+ [org.jetlang.channels MemoryChannel])
+ (:use expectations jreg.core))
+
+(expect Callback (->callback identity))
+(expect 1 (let [a (atom 0)]
+ (.onMessage (->callback #(swap! % inc)) a)
+ @a))
+
+(expect 1
+ (let [chan (MemoryChannel.)
+ executor (SynchronousDisposingExecutor.)
+ a (atom 0)]
+ (subscribe chan executor #(swap! % inc))
+ (.publish chan a)
+ @a))

0 comments on commit e662c85

Please sign in to comment.