Last active
March 27, 2017 16:40
-
-
Save djwhitt/bd54b89937e13f97f9fb37858b1476ca 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
| (let [event-chan (chan 1) | |
| t-out (timeout 5000) | |
| start-ts (.getTime (js/Date.))] | |
| (go | |
| (loop [] | |
| (>! event-chan :some-event) | |
| (let [[_ ch] (alts! [t-out event-chan] :priority true)] | |
| (cond | |
| (and (= ch event-chan) | |
| (< (- (.getTime (js/Date.)) start-ts) 10000)) | |
| (recur) | |
| (= ch t-out) | |
| (js/console.log "timeout happened")))) | |
| (js/console.log (str "runtime: " (- (.getTime (js/Date.)) start-ts))))) | |
| ;; => runtime: 10001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment