File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
src/clojure/clojure/core/async/impl
test/clojure/clojure/core Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 16
16
17
17
(set! *warn-on-reflection* true )
18
18
19
+ (defmacro assert-unlock [lock test msg]
20
+ `(when-not ~test
21
+ (.unlock ~lock)
22
+ (throw (new Exception (str " Assert failed: " ~msg " \n " (pr-str '~test)))))) ; ;; AssertionError
23
+
19
24
(defn box [val]
20
25
(reify clojure.lang.IDeref
21
26
(deref [_] val)))
118
123
nil ))))
119
124
(do
120
125
(when (impl/active? handler)
121
- (.AddFirst puts [handler val])) ; ;; .add
126
+ (assert-unlock mutex
127
+ (< (.Count puts) impl/MAX-QUEUE-SIZE) ; ;; .size
128
+ (str " No more than " impl/MAX-QUEUE-SIZE
129
+ " pending puts are allowed on a single channel."
130
+ " Consider using a windowed buffer." ))
131
+ (.AddLast puts [handler val])) ; ;; .add
122
132
(.unlock mutex)
123
133
nil ))))))
124
134
216
226
(box nil )
217
227
nil ))
218
228
(do
219
- (.AddFirst takes handler) ; ;; .add
229
+ (assert-unlock mutex
230
+ (< (.Count takes) impl/MAX-QUEUE-SIZE) ; ;; .size
231
+ (str " No more than " impl/MAX-QUEUE-SIZE
232
+ " pending takes are allowed on a single channel." ))
233
+ (.AddLast takes handler) ; ;; .add
220
234
(.unlock mutex)
221
235
nil )))))))
222
236
Original file line number Diff line number Diff line change 11
11
(ns ^{:skip-wiki true }
12
12
clojure.core.async.impl.protocols )
13
13
14
+
15
+ (def ^:const ^int MAX-QUEUE-SIZE 1024 )
16
+
14
17
(defprotocol ReadPort
15
18
(take! [port fn1-handler] " derefable val if taken, nil if take was enqueued" ))
16
19
Original file line number Diff line number Diff line change 109
109
" When on-caller? requested, but no reader can consume the value,
110
110
put!'s callback executes on a different thread." ))
111
111
112
+ (deftest limit-async-take!-put!
113
+ (testing " async put! limit"
114
+ (let [c (chan )]
115
+ (dotimes [x 1024 ]
116
+ (put! c x))
117
+ (is (thrown? Exception ; ;;AssertionError
118
+ (put! c 42 )))
119
+ (is (= (<!! c) 0 )))) ; ; make sure the channel unlocks
120
+ (testing " async take! limit"
121
+ (let [c (chan )]
122
+ (dotimes [x 1024 ]
123
+ (take! c (fn [x])))
124
+ (is (thrown? Exception ; ;;AssertionError
125
+ (take! c (fn [x]))))
126
+ (is (nil? (>!! c 42 )))))) ; ; make sure the channel unlocks
127
+
112
128
(deftest puts-fulfill-when-buffer-available
113
129
(is (= :proceeded
114
130
(let [c (chan 1 )
You can’t perform that action at this time.
0 commit comments