Last active
February 25, 2018 18:42
-
-
Save noisesmith/335606e11056ae6aca0fe983e92d6bf9 to your computer and use it in GitHub Desktop.
simple usage of halt-when with clojure core.async
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
+user=> (def c (>/chan 1 (halt-when even?))) | |
#'user/c | |
+user=> (>/take! c println) | |
nil | |
+user=> (>/put! c 1) | |
true1 | |
+user=> (>/take! c println) | |
nil | |
+user=> (>/put! c 3) | |
true | |
user=> 3 | |
+user=> (>/take! c println) | |
nil | |
+user=> (>/put! c 2) | |
true | |
nil | |
+user=> (>/take! c println) | |
nil | |
nil |
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
+user=> (def c (>/chan 1 (halt-when even? (fn [x y] (println "halted on" x "with" y))))) | |
#'user/c | |
+user=> (>/take! c (fn [x] (println \newline "x:" x))) | |
nil | |
+user=> (>/put! c 1) | |
true | |
user=> | |
x: 1 | |
+user=> (>/put! c 3) | |
true | |
+user=> (>/take! c (fn [x] (println \newline "x:" x))) | |
x: 3 | |
nil | |
+user=> (>/take! c (fn [x] (println \newline "x:" x))) | |
nil | |
+user=> (>/put! c 2) | |
halted on #object[clojure.core.async.impl.buffers.FixedBuffer 0x2b9bbaa8 clojure.core.async.impl.buffers.FixedBuffer@2b9bbaa8] with 2 | |
true | |
user=> | |
x: nil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment