diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2011-09-29 22:51:47 -0500 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2011-09-29 22:51:47 -0500 |
commit | e8d694d79da9f5f7e4ac22991b904eaaa4cd6db0 (patch) | |
tree | c8d90168459afc33a8a1544b46de69be8316baf0 /src/main/clojure | |
parent | ab7dfd6e942e5112e730e786ab6b2ee4798abdd2 (diff) |
Add utility function do-callbacks!
Diffstat (limited to 'src/main/clojure')
-rw-r--r-- | src/main/clojure/org/gnu/clojure/gnunet/peer.clj | 6 | ||||
-rw-r--r-- | src/main/clojure/org/gnu/clojure/gnunet/topology_events.clj | 8 | ||||
-rw-r--r-- | src/main/clojure/org/gnu/clojure/gnunet/util.clj | 5 |
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))) |