summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2011-09-29 22:51:47 -0500
committerDavid Barksdale <amatus.amongus@gmail.com>2011-09-29 22:51:47 -0500
commite8d694d79da9f5f7e4ac22991b904eaaa4cd6db0 (patch)
treec8d90168459afc33a8a1544b46de69be8316baf0 /src
parentab7dfd6e942e5112e730e786ab6b2ee4798abdd2 (diff)
Add utility function do-callbacks!
Diffstat (limited to 'src')
-rw-r--r--src/main/clojure/org/gnu/clojure/gnunet/peer.clj6
-rw-r--r--src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj8
-rw-r--r--src/main/clojure/org/gnu/clojure/gnunet/util.clj5
3 files changed, 11 insertions, 8 deletions
diff --git a/src/main/clojure/org/gnu/clojure/gnunet/peer.clj b/src/main/clojure/org/gnu/clojure/gnunet/peer.clj
index fb98fd7..3cd1cf9 100644
--- a/src/main/clojure/org/gnu/clojure/gnunet/peer.clj
+++ b/src/main/clojure/org/gnu/clojure/gnunet/peer.clj
@@ -123,12 +123,10 @@
(defn selector-loop!
[selector callbacks]
- (doseq [callback (queue-seq! callbacks)]
- (callback))
+ (do-callbacks! (queue-seq! callbacks))
(.select selector)
(let [selected-keys (.selectedKeys selector)]
- (doseq [selection-key selected-keys]
- ((.attachment selection-key)))
+ (do-callbacks! (map #(.attachment %) selected-keys))
(.clear selected-keys))
(recur selector callbacks))
diff --git a/src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj b/src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj
index aaaf9a3..4d39c23 100644
--- a/src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj
+++ b/src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj
@@ -1,8 +1,8 @@
-(ns org.gnu.clojure.gnunet.topology_events)
+(ns org.gnu.clojure.gnunet.topology_events
+ (:use org.gnu.clojure.gnunet.util))
(defn notify-new-remote-peer!
[peer remote-peer]
- (let [callbacks (:new-peer-callbacks (deref (:topology-agent peer)))]
- (doseq [callback! callbacks]
- (callback! peer remote-peer))))
+ (do-callbacks! (:new-peer-callbacks (deref (:topology-agent peer)))
+ peer remote-peer))
diff --git a/src/main/clojure/org/gnu/clojure/gnunet/util.clj b/src/main/clojure/org/gnu/clojure/gnunet/util.clj
index 9914dfd..3b4d5ff 100644
--- a/src/main/clojure/org/gnu/clojure/gnunet/util.clj
+++ b/src/main/clojure/org/gnu/clojure/gnunet/util.clj
@@ -50,3 +50,8 @@
(assoc _map _key
(conj old-val (second kv)))))
_map (partition 2 kvs)))
+
+(defn do-callbacks!
+ [callback-seq & args]
+ (doseq [callback! callback-seq]
+ (apply callback! args)))