Skip to content

Instantly share code, notes, and snippets.

@uwo
Last active July 17, 2018 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uwo/61b3d2f6811e57d3ac387959a5e78c0b to your computer and use it in GitHub Desktop.
Save uwo/61b3d2f6811e57d3ac387959a5e78c0b to your computer and use it in GitHub Desktop.
async utils

deps.edn

{:deps {gist-uwo/autil {:git/url "https://gist.github.com/uwo/61b3d2f6811e57d3ac387959a5e78c0b"
                        :sha "9a53fbd9ff3812971f34b99c088dd62672fb02c7"}}}
(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))}))
{: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