This file contains hidden or 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
(require '[clojure.core.async :as a]) | |
(defn- seq-of-chan "Creates a lazy seq from a core.async channel." [c] | |
(lazy-seq | |
(let [fst (a/<!! c)] | |
(if (nil? fst) nil (cons fst (seq-of-chan c)) )))) | |
(defn map-pipeline-async "Map for asynchronous functions, backed by clojure.core.async/pipeline-async . | |
From an asynchronous function af, and a seq coll, creates a lazy seq that is the result of applying the asynchronous function af to each element of coll. |
This file contains hidden or 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
(require '[clojure.core.async :as a]) | |
(defn make-promise-listener! | |
"Creates a function that attaches handlers to Clojure promises. | |
Behind the scences, fires a loop in another logical thread that scans every refresh-period ms the promises that have been registered for completion, | |
and executes the each handler on the corresponding value." | |
[{:keys [refresh-period] | |
:or {refresh-period 10}}] | |
(let [next-index! (let [a (atom -1)] #(swap! a inc)) ;; to get unique keys to put in the map. | |
state (atom {})] ;; map of dummy unique keys to pending promise-handler pairs |
NewerOlder