This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ping-forever-core-async | |
[host ms-pause] | |
(let [termination-ch (chan) | |
termination-fn #(put! termination-ch :die)] | |
(go-loop [sleep-ch (timeout 0)] | |
(let [[_ ch] (alts! [sleep-ch termination-ch])] | |
(if (= ch sleep-ch) | |
(do | |
(println "Pinging" host) | |
(recur (timeout ms-pause))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;; STUBBING A FUNCTION | |
(defn select-id [id] | |
; real code would connect to db, just simulating here | |
{:col1 (rand-int 101) | |
:col2 (rand-nth ["Joe" "Bob" "Bill" "Sally"])}) | |
(s/def ::col1 nat-int?) | |
(s/def ::col2 (s/with-gen string? #(gen/such-that (complement empty?) (gen/string-alphanumeric)))) | |
(s/def ::db-row (s/keys :req-un [::col1 ::col2])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[java.util.concurrent Callable | |
CountDownLatch | |
Executors | |
Semaphore | |
TimeUnit]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Examples of creating and joining threads in clojure | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(let [numthreads 5 |