Permalink
Browse files

Added :scatter-gather to a-except

  • Loading branch information...
1 parent 8e8820f commit cac7543a52791467278ae6c80a573329d63775ae @duey-sonian duey-sonian committed May 2, 2011
Showing with 45 additions and 17 deletions.
  1. +28 −11 src/conduit/core.clj
  2. +17 −6 test/conduit/test_core.clj
View
39 src/conduit/core.clj
@@ -354,29 +354,46 @@
(defn a-except [p catch-p]
(letfn [(a-except [f catch-f x]
- (try
- (let [[new-x new-f] (f x)]
- [new-x (partial a-except new-f catch-f)])
- (catch Exception e
- (let [[new-x new-catch] (catch-f [e x])]
- [new-x (partial a-except f new-catch)]))))]
+ (try
+ (let [[new-x new-f] (f x)]
+ [new-x (partial a-except new-f catch-f)])
+ (catch Exception e
+ (let [[new-x new-catch] (catch-f [e x])]
+ [new-x (partial a-except f new-catch)]))))
+ (a-except-sg [f catch-f x]
+ (try
+ (let [result-f (f x)]
+ (fn []
+ (try
+ (let [[new-x new-f] (result-f)]
+ [new-x (partial a-except-sg new-f catch-f)])
+ (catch Exception e
+ (let [[new-x new-catch] (catch-f [e x])]
+ [new-x (partial a-except-sg f new-catch)])))))
+ (catch Exception e
+ (fn []
+ (let [[new-x new-catch] (catch-f [e x])]
+ [new-x (partial a-except-sg f new-catch)])))))]
{:parts (:parts p)
:reply (partial a-except
(:reply p)
(:reply catch-p))
:no-reply (partial a-except
(:no-reply p)
(:no-reply catch-p))
+ :scatter-gather (partial a-except-sg
+ (:scatter-gather p)
+ (:reply catch-p))
:created-by :a-except
:args [p catch-p]}))
(defn a-finally [p final-p]
(letfn [(a-finally [f final-f x]
- (try
- (let [[new-x new-f] (f x)]
- [new-x (partial a-finally new-f final-f)])
- (finally
- (final-f x))))]
+ (try
+ (let [[new-x new-f] (f x)]
+ [new-x (partial a-finally new-f final-f)])
+ (finally
+ (final-f x))))]
{:parts (:parts p)
:reply (partial a-finally
(:reply p)
View
23 test/conduit/test_core.clj
@@ -425,8 +425,19 @@
:no-reply (fn this-fn [_]
[[2] this-fn])
:reply (fn this-fn [_]
- [[1] this-fn]))
- tx (a-except x (a-arr (constantly nil)))]
+ [[1] this-fn])
+ :scatter-gather (fn this-fn [x]
+ (if (zero? (mod x 3))
+ (throw (Exception. "Div by 3"))
+ (fn []
+ [[3] this-fn]))))
+ tx (a-except x pass-through)
+ ty (a-except te
+ (a-arr (fn [[e _]]
+ 10)))
+ tz (a-except x
+ (a-arr (fn [[e _]]
+ 15)))]
(is (thrown? Exception
(conduit-map te (range 5))))
@@ -438,10 +449,10 @@
(conduit-map tx
(range 5))))
- #_(is (= []
- (conduit-map (a-comp (a-all tx tx)
- pass-through)
- (range 5))))))
+ (is (= [[10 15] [2 3] [10 3] [6 15] [10 3]]
+ (conduit-map (a-comp (a-all ty tz)
+ pass-through)
+ (range 5))))))
(deftest test-a-finally
(let [main-count (atom 0)

0 comments on commit cac7543

Please sign in to comment.