{:deps {gist-uwo/autil {:git/url "https://gist.github.com/uwo/61b3d2f6811e57d3ac387959a5e78c0b"
:sha "9a53fbd9ff3812971f34b99c088dd62672fb02c7"}}}
Last active
July 17, 2018 21:51
-
-
Save uwo/61b3d2f6811e57d3ac387959a5e78c0b to your computer and use it in GitHub Desktop.
async utils
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
(ns autil | |
(:require [clojure.core.async :as a])) | |
(defn drain! | |
"Close ch and discard all items on it. Returns nil." | |
[ch] | |
(a/close! ch) | |
(a/go-loop [] | |
(when-some [_ (a/<! ch)] (recur))) | |
nil) | |
(defn make-print-ch | |
([] (make-print-ch (a/chan 100))) | |
([prn-ch] | |
(a/go-loop [] | |
(when-some [x (a/<! prn-ch)] | |
(apply print x) | |
(flush)) | |
(recur)) | |
{:prn-ch prn-ch | |
:prn-fn (fn [& args] (a/put! prn-ch args))})) |
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
{:paths ["."] | |
:deps | |
{org.clojure/core.async {:mvn/version "0.4.474"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment