Permalink
Browse files

Add :scatter-gather to a-finally

  • Loading branch information...
1 parent cac7543 commit c5c38b896b219839c9e9596199ab17682f96c2d6 @duey-sonian duey-sonian committed May 3, 2011
Showing with 38 additions and 2 deletions.
  1. +14 −0 src/conduit/core.clj
  2. +24 −2 test/conduit/test_core.clj
View
@@ -393,6 +393,17 @@
(let [[new-x new-f] (f x)]
[new-x (partial a-finally new-f final-f)])
(finally
+ (final-f x))))
+ (a-finally-sg [f final-f x]
+ (try
+ (let [result-f (f x)]
+ (fn []
+ (try
+ (let [[new-x new-f] (result-f)]
+ [new-x (partial a-finally-sg new-f final-f)])
+ (finally
+ (final-f x)))))
+ (finally
(final-f x))))]
{:parts (:parts p)
:reply (partial a-finally
@@ -401,6 +412,9 @@
:no-reply (partial a-finally
(:no-reply p)
(:no-reply final-p))
+ :scatter-gather (partial a-finally-sg
+ (:scatter-gather p)
+ (:reply final-p))
:created-by :a-finally
:args [p final-p]}))
View
@@ -456,21 +456,43 @@
(deftest test-a-finally
(let [main-count (atom 0)
+ secondary-count (atom 0)
finally-count (atom 0)
te (a-arr (fn [x]
(when (even? x)
(throw (Exception. "An even int")))
(swap! main-count inc)
(* 2 x)))
+ x (assoc te
+ :scatter-gather (fn this-fn [x]
+ (when (zero? (mod x 3))
+ (swap! main-count inc)
+ (throw (Exception. "Div by 3")))
+ (fn []
+ (when (even? x)
+ (swap! secondary-count inc)
+ (throw (Exception. "Even!!!")))
+ [[(* 10 x)] this-fn])))
tx (a-finally te (a-arr (fn [x]
+ (swap! finally-count inc)
+ x)))
+ ty (a-finally x (a-arr (fn [x]
(swap! finally-count inc)
x)))
- tf (a-except tx (a-arr (constantly nil)))]
+ tf (a-except tx (a-arr (constantly nil)))
+ tz (a-except ty (a-arr (fn [[_ x]] x)))]
(is (= [nil 2 nil 6 nil]
(conduit-map tf (range 5))))
(is (= 2 @main-count))
(is (= 5 @finally-count))
-))
+
+ (reset! main-count 0)
+ (reset! secondary-count 0)
+ (is (= [[0 0] [10 10] [2 2] [3 3] [4 4] [50 50]]
+ (conduit-map (a-comp (a-all tz tz)
+ pass-through)
+ (range 6))))
+ ))
(deftest test-test-conduit
(def-proc bogus [x]

0 comments on commit c5c38b8

Please sign in to comment.