Skip to content

Instantly share code, notes, and snippets.

@rwat rwat/pg.util.clj
Created Apr 30, 2018

Embed
What would you like to do?
(ns pg.util
(:require [clojure.core.async :refer [>! <! >!! <!! alts! alts!! chan go go-loop put! take! thread timeout close!] :as async]))
;; synchronous; takes from channel argument if something is available, else returns nil
(def maybe-take!
(let [closed-ch (doto (chan) (close!))]
(fn [ch]
(let [[x port] (alts!! [ch closed-ch] {:priority true})]
(when (= port ch)
x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.