Created
December 22, 2014 10:28
-
-
Save slipset/d299bf015aa341ee5852 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 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