Skip to content

Commit

Permalink
FIXED #9. Added support for custom merge function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sun Ning committed Apr 7, 2014
1 parent 9ee7016 commit 4089ba6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/slacker/client/cluster.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion test/slacker/test/client/cluster.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))

0 comments on commit 4089ba6

Please sign in to comment.