-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.lisp
54 lines (46 loc) · 1.96 KB
/
reader.lisp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
;;;; reader.lisp --- An example program demonstrating the reader.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; Loading this file does not terminate.
;; mark-start::body
;; For managing the lifetime of readers (e.g. for short-lived
;; readers), the `with-participant' macro can used. It will take care
;; of disposing of the `reader' instance after it has been used, also
;; in case of non-local exist.
;;
;; Note: this form will block until an event is received.
;; mark-start::with-participant
(rsb:with-participant (reader :reader "/example/informer")
(let ((event (rsb.patterns.reader:receive reader)))
(format t "Received event: ~A~%" event)
event)) ; return the event
;; mark-end::with-participant
;; This will create a `reader' instance that receives events which are
;; sent to the channel designated by the scope "/example/reader". The
;; reader will use all transports which are enabled in the
;; configuration with their respective configured options.
;;
;; Note: the `receive' call will block until an event is received.
;;
;; mark-start::variable
(defvar *reader* (rsb:make-participant :reader "/example/informer"))
;; mark-start::receive/block
(let ((event (rsb.patterns.reader:receive *reader* :block? t))) ; block? defaults to t
(format t "Received event: ~A~%" event)
event) ; return the event
;; mark-end::receive/block
;; It is also possible to use `rsb.patterns.reader:receive' in a
;; non-blocking mode. In that case, an `event' or nil is returned.
;; mark-start::receive/noblock
(let ((event (rsb.patterns.reader:receive *reader* :block? nil)))
(format t "~:[Did not receive an event~;Received event: ~:*~A~]~%"
event)
event) ; return the event, or nil
;; mark-end::receive/noblock
;; The reader will participate in the channel until it is garbage
;; collected or explicitly detached using the `rsb:detach' function.
(rsb:detach *reader*)
;; mark-end::variable
;; mark-end::body