Skip to content

Commit 8d732ce

Browse files
committed
ASYNC-257 Make channels Datafiable
1 parent 2ad3e0e commit 8d732ce

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/clojure/clojure/core/async.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ to catch and handle."
9292
buffer must be specified. ex-handler must be a fn of one argument -
9393
if an exception occurs during transformation it will be called with
9494
the Throwable as an argument, and any non-nil return value will be
95-
placed in the channel."
95+
placed in the channel. Channels implement Datafiable; use datafy
96+
to obtain the state of the channel and its buffer."
9697
([] (chan nil))
9798
([buf-or-n] (chan buf-or-n nil))
9899
([buf-or-n xform] (chan buf-or-n xform nil))

src/main/clojure/clojure/core/async/impl/channels.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,15 @@
303303
(add! buf val)
304304
(catch Throwable t
305305
(handle buf exh t)))))))))
306+
307+
(extend-protocol clojure.core.protocols/Datafiable
308+
ManyToManyChannel
309+
(datafy [c]
310+
(let [b (.buf c)]
311+
{:buffer-type (if b
312+
(-> b class .getSimpleName symbol)
313+
:none)
314+
:buffer-count (count b)
315+
:put-count (count (.puts c))
316+
:take-count (count (.takes c))
317+
:closed? (impl/closed? c)})))

0 commit comments

Comments
 (0)