Skip to content

Commit ee4a7ec

Browse files
committed
Fixes consume! for multi threading purpose
1 parent 8abc5df commit ee4a7ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/jtk_dvlp/async.cljc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,18 @@
102102
[chs]
103103
(map vector chs))
104104

105-
(defn consume
106-
"Consumes channel `ch` executing function `f` for every value on channel. Execution will be asynchron, call returns immediately with `nil`."
105+
(defn consume!
106+
"Consumes channel `ch` executing function `f` for every value on channel. Spawns a new thread for Execution. Execution will be asynchron. Call returns immediately with `nil`."
107107
[ch f]
108-
(map f ch)
108+
#?(:clj
109+
(future
110+
(loop [val (async/<!! ch)]
111+
(when val
112+
(f val)
113+
(recur (async/<!! ch)))))
114+
115+
:cljs
116+
(map f ch))
109117
nil)
110118

111119
(defn smap

0 commit comments

Comments
 (0)