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 throttle-chan [input] | |
(let [throttle-chan (chan) | |
output-chan (chan)] | |
(go | |
(loop [throttle-msec nil] | |
(let [t-chan (when-not (= :disabled throttle-msec) | |
(timeout throttle-msec)) | |
[val c] (alt! [input throttle-chan])] | |
(if (= c throttle-chan) | |
(recur val) |
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
(def a (chan)) | |
(def b (chan)) | |
(go | |
(>! b (<! a))) | |
(go | |
(>! a (<! b))) |
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
(ns async-examples.load-balancer | |
(:require [clojure.core.async :refer :all])) | |
;; Let's assume we have a DB, and it holds the following pairs of name/ages | |
(def db-store | |
{:john 42 | |
:amy 33 | |
:jill 3 |
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
(ns cljs.core.async.impl.dispatch | |
(:require [cljs.core.async.impl.buffers :as buffers])) | |
(def message-channel nil) | |
(def tasks (buffers/ring-buffer 32)) | |
(def ^:boolean running? false) | |
(def ^:boolean queued? false) | |
(def TASK_BATCH_SIZE 1024) |
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 print-fn [x] | |
(.log js/console x)) | |
(set! *print-fn* print-fn) | |
(def c (chan)) | |
(def MILLION 1000000) | |
(def TEN-THOUSAND 10) | |
(def AMOUNT MILLION) |
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
(def c (chan)) | |
(defn drain [c] | |
(go | |
(loop [col []] | |
(if-let [v (<! c)] | |
(recur (conj col v)) | |
col)))) |
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
(defrecord Jmp [value block] | |
IInstruction | |
(reads-from [this] [value]) | |
(writes-to [this] []) | |
(block-references [this] [block]) | |
ITerminator | |
(terminate-block [this state-sym _] | |
`(do (aset-all! ~state-sym ~VALUE-IDX ~value ~STATE-IDX ~block) | |
:recur))) |
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
(go (->> urls | |
(map async-http-request) | |
doall | |
(apply map< vector) | |
<!)) |
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
(ns dataflow-prototype.core | |
(:require [clojure.core.async :refer :all] | |
[clojure.edn :refer [read-string]])) | |
(defprotocol Lifecycle | |
(start [service]) | |
(stop [service])) | |
(defprotocol DataFlowNode |
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
(ns rabbit-mq-test.core | |
(:require [clojure.core.async :refer :all]) | |
(:import [com.rabbitmq.client ConnectionFactory Connection Channel QueueingConsumer Consumer DefaultConsumer])) | |
(set! *warn-on-reflection* true) | |
(defprotocol Lifecycle | |
(start [service]) | |
(stop [service])) |