Skip to content

Instantly share code, notes, and snippets.

@slipset
Created December 22, 2014 10:28
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 slipset/d299bf015aa341ee5852 to your computer and use it in GitHub Desktop.
Save slipset/d299bf015aa341ee5852 to your computer and use it in GitHub Desktop.
(ns my-ns.core
(:require [clojure.core.async :refer
[timeout thread alt! alts! chan go-loop <! >! put! chan close!]]))
(defn takes-a-while [chan x]
(println "starting long running query")
(thread (Thread/sleep 5000)
(put! chan x)))
(defn run-it []
(let [c (chan)]
(takes-a-while c 5)
(go-loop []
(let [[val chnl] (alts! [c (timeout 500)])]
(if (= c chnl)
(println "got value at last" val)
(do
(println "still waiting...")
(recur)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment