Last active
August 29, 2015 13:55
-
-
Save janherich/8738585 to your computer and use it in GitHub Desktop.
time bound channel
This file contains 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
(defn create-cancel-channel | |
[channel-to-notify timeout-ms] | |
(let [cancel-channel (async/chan) | |
timeout-channel (async/timeout timeout-ms)] | |
(async/go | |
(let [[_ c] (async/alts! [cancel-channel timeout-channel])] | |
(when (= c timeout-channel) | |
(async/close! cancel-channel) | |
(async/close! channel-to-notify)))) | |
cancel-channel)) | |
;; transport channel | |
(def transport-channel (async/chan)) | |
;; cancel-channel | |
(def cancel-channel (create-cancel-channel transport-channel 2000)) | |
;; to cancel the transport channel timeout, just close the cancel-channel | |
(async/close! cancel-channel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment