Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
straszheimjeffrey committed Dec 30, 2011
1 parent 2802d36 commit f0f8217
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Here are some specific complexity issues that I've found:
request.

2. Often the data you need in one part of the control flow isn't
visible because it is created and consumed elsehwere.
visible because it is created and consumed elsewhere.

3. What you need to compute tends to not change much, but how you
compute it often does. That is, new bits of data become relavent,
Expand Down
11 changes: 9 additions & 2 deletions src/kiln/kiln.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
(:cleanup-success clay)
(:cleanup-failure clay)))

(defn- run-clay
[kiln clay]
(try
(dosync (alter (:vals kiln) assoc (:id clay) ::running))
((:fun clay) kiln)
(finally
(dosync (alter (:vals kiln) assoc (:id clay) nil)))))

(defn fire
"Run the clay within the kiln to compute/retrieve its value."
[kiln clay] ; the clay can be a coal
Expand All @@ -46,8 +54,7 @@
(if (::clay? clay)
(do (when-let [pres (:pre-compute clay)]
(doseq [pre pres] (fire kiln pre)))
(dosync (alter (:vals kiln) assoc (:id clay) ::running))
(let [result ((:fun clay) kiln)]
(let [result (run-clay kiln clay)]
(dosync
(alter (:vals kiln) assoc (:id clay) result)
(when (has-cleanup? clay)
Expand Down
13 changes: 13 additions & 0 deletions test/kiln/kiln_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns kiln.kiln-test
(use clojure.test)
(use slingshot.slingshot)
(use kiln.kiln))

(deftest test-new-kiln
Expand Down Expand Up @@ -85,6 +86,18 @@
(fire k bob!)
(is (= @store [k]))))

(declare loopy-clay)
(defclay loopy-clay (?? loopy-clay))

(deftest test-loopy-clay
(let [k (new-kiln)]
(is (= :exception-thrown
(try+
(fire k loopy-clay)
(catch [:type :kiln-loop] {:keys [clay kiln]}
(is (= clay loopy-clay))
(is (= kiln k))
:exception-thrown))))))

(comment

Expand Down

0 comments on commit f0f8217

Please sign in to comment.