Skip to content

Commit

Permalink
Fixed exception handling in README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Barrett committed Jan 8, 2015
1 parent 418857d commit f459073
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,33 @@ unneeded work).
```clojure
;; Core map does no work after an exception.
(let [counter (atom 0)]
(doall (map #(do (inc %) (swap! counter inc)) (cons nil (range 100))))
(try
(doall (map #(do (inc %) (swap! counter inc))
(cons nil (range 100))))
(catch Exception e))
(= @counter 0))
;; Core pmap does ncpus + 2 work after an exception.
(let [counter (atom 0)]
(doall (pmap #(do (inc %) (swap! counter inc)) (cons nil (range 100))))
(try
(doall (pmap #(do (inc %) (swap! counter inc))
(cons nil (range 100))))
(catch Exception e))
(Thread/sleep 1000) ; wait 1 second for tasks to complete
(= @counter (+ 2 (cp/ncpus))))
;; Claypoole eager pmap does pool size * 2 work after an exception.
(let [counter (atom 0)]
(doall (cp/pmap 3 #(do (inc %) (swap! counter inc)) (cons nil (range 100))))
(try
(doall (cp/pmap 3 #(do (inc %) (swap! counter inc))
(cons nil (range 100))))
(catch Exception e))
(Thread/sleep 1000) ; wait 1 second for tasks to complete
(= @counter 6))
;; Claypoole lazy pmap does pool size work after an exception.
(let [counter (atom 0)]
(doall (lazy/pmap 3 #(do (inc %) (swap! counter inc)) (cons nil (range 100))))
(try
(doall (lazy/pmap 3 #(do (inc %) (swap! counter inc))
(cons nil (range 100))))
(catch Exception e))
(Thread/sleep 1000) ; wait 1 second for tasks to complete
(= @counter 3))
```
Expand Down

0 comments on commit f459073

Please sign in to comment.