Created
April 30, 2018 14:08
-
-
Save rwat/a4c45411897d0698ea8f46d35d5a558d to your computer and use it in GitHub Desktop.
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 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