-
-
Save jaen/047a57e5273fd7b7c920 to your computer and use it in GitHub Desktop.
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
(def pause-chan (async/chan)) | |
(defn pause! [] | |
(let [pause-end-chan (async/chan)] | |
(async/put! pause-chan pause-end-chan) | |
(fn [] | |
(async/put! pause-end-chan :whatever)))) | |
(async/go-loop [] | |
(let [[pause _] (async/alts! [pause-chan] :default nil)] | |
(when pause | |
(async/<! pause))) ; take to pause the go-loop | |
(println "doing some work") | |
(async/<! (async/timeout 2000)) | |
(println "done some work") | |
(recur)) | |
(def unpause! (pause!)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment