-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
41 lines (27 loc) · 1.14 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# clj-ring-buffer
A lockless ring buffer supporting an arbitrary number of producers and
consumer. This is a VERY fast mechanism for inter-thread communication.
## Usage
(make-ring-buffer num-of-producers num-of-consumers size-of-ring-buffer))
make-ring-buffer returns a map containing producer functions, consumer functions, and the underlying ring-buffer itself.
(let [{producer-1 :producer-1 consumer-1 :consumer-1 producer-2 :producer-2 consumer-2 :consumer-2
r-buffer :ring-buffer}
(rb/make-ring-buffer 2 2 4)]
(producer-1 "A")
;;will return false if the buffer is full with respect to
;;producer-1 and the data could not be inserted into the ring buffer.
;;In such a case, the production should be retried by the client.
(producer-2 "B")
(consumer-1)
;;returns "A"
(empty-buffer? r-buffer 1)
;;returns true. Buffer is empty for consumer-1
(consumer-2)
;;returns "B"
(empty-buffer? r-buffer 2)
;;returns true. Buffer is empty for consumer-2
;;view the contents of the ring buffer
(peek r-buffer)
;;("A","B", nil, nil)
## License
Information Wants To Be Free