1
+ ; ; Copyright (c) Rich Hickey and contributors. All rights reserved.
2
+ ; ; The use and distribution terms for this software are covered by the
3
+ ; ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4
+ ; ; which can be found in the file epl-v10.html at the root of this distribution.
5
+ ; ; By using this software in any fashion, you are agreeing to be bound by
6
+ ; ; the terms of this license.
7
+ ; ; You must not remove this notice, or any other, from this software.
8
+
9
+ (ns ^{:skip-wiki true }
10
+ clojure.core.async.impl.protocols )
11
+
12
+
13
+ (def ^:const ^{:tag 'int} MAX-QUEUE-SIZE 1024 )
14
+
15
+ (defprotocol ReadPort
16
+ (take! [port fn1-handler] " derefable val if taken, nil if take was enqueued" ))
17
+
18
+ (defprotocol WritePort
19
+ (put! [port val fn1-handler] " derefable boolean (false iff already closed) if handled, nil if put was enqueued. Must throw on nil val." ))
20
+
21
+ (defprotocol Channel
22
+ (close! [chan])
23
+ (closed? [chan]))
24
+
25
+ (defprotocol Handler
26
+ (active? [h] " returns true if has callback. Must work w/o lock" )
27
+ (blockable? [h] " returns true if this handler may be blocked, otherwise it must not block" )
28
+ (lock-id [h] " a unique id for lock acquisition order, 0 if no lock" )
29
+ (commit [h] " commit to fulfilling its end of the transfer, returns cb. Must be called within lock" ))
30
+
31
+ (defprotocol ABuffer ; ;; Rename Buffer because of conflict with System.Buffer
32
+ (full? [b] " returns true if buffer cannot accept put" )
33
+ (remove! [b] " remove and return next item from buffer, called under chan mutex" )
34
+ (add!* [b itm] " if room, add item to the buffer, returns b, called under chan mutex" )
35
+ (close-buf! [b] " called on chan closed under chan mutex, return ignored" ))
36
+
37
+ (defn add!
38
+ ([b] b)
39
+ ([b itm]
40
+ (assert (not (nil? itm)))
41
+ (add!* b itm)))
42
+
43
+ (defprotocol Executor
44
+ (exec [e runnable] " execute runnable asynchronously" ))
45
+
46
+ ; ; Defines a buffer that will never block (return true to full?)
47
+ (defprotocol UnblockingBuffer )
0 commit comments