From 4089ba6e2b9f5c39103b22e5f7b8f2f3f38e3e37 Mon Sep 17 00:00:00 2001 From: Sun Ning Date: Mon, 7 Apr 2014 11:29:25 +0800 Subject: [PATCH] FIXED #9. Added support for custom merge function. --- src/slacker/client/cluster.clj | 10 +++++++--- test/slacker/test/client/cluster.clj | 11 ++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/slacker/client/cluster.clj b/src/slacker/client/cluster.clj index 7e318a8..25c24f8 100644 --- a/src/slacker/client/cluster.clj +++ b/src/slacker/client/cluster.clj @@ -97,12 +97,16 @@ :nested (map :cause (filter :cause call-results))}} :else - (let [valid-results (remove :cause call-results)] - {:result (case (grouping-results) + (let [valid-results (remove :cause call-results) + grouping-results-config (grouping-results)] + {:result (case grouping-results-config :single (:result (first valid-results)) :vector (mapv :result valid-results) :map (into {} (map #(vector (:server %) (:result %)) - valid-results)))})))) + valid-results)) + (if (fn? grouping-results-config) + (grouping-results-config valid-results) + (throw (ex-info "Unsupported grouping-results value"))))})))) (deftype GroupedPromise [grouping-fn promises] IDeref diff --git a/test/slacker/test/client/cluster.clj b/test/slacker/test/client/cluster.clj index 234498b..1afdb2d 100644 --- a/test/slacker/test/client/cluster.clj +++ b/test/slacker/test/client/cluster.clj @@ -50,4 +50,13 @@ ["1" "2"] [{:result 1} {:result 2}])] - (is (= 1 (-> r :result (get "1")))))) + (is (= 1 (-> r :result (get "1"))))) + (let [grf (fn [] + (fn [results] + (reduce + (map :result results)))) + r (group-call-results grf + :all + ["1" "2"] + [{:result 1} + {:result 2}])] + (is (= 3 (:result r)))))