@@ -1194,7 +1194,40 @@ interact with an [[https://github.com/jupyter-widgets/ipyleaflet][ipyleaflet]] m
11941194** TODO =jupyter-ioloop=
11951195** TODO =jupyter-channel-ioloop=
11961196** TODO =jupyter-zmq-channel-ioloop=
1197- ** TODO =jupyter-comm-layer=
1197+ ** =jupyter-comm-layer=
1198+
1199+ The =jupyter-comm-layer= class abstracts the sending/receiving of messages
1200+ between a kernel and a =jupyter-kernel-client= so that a =jupyter-kernel-client=
1201+ does not need to be concerned with the underlying way that messages are
1202+ communicated. It also allows one to build up layers of event handling in which
1203+ subsets of events may be handled on one layer and the remaining events handled
1204+ by the remaining layers.
1205+
1206+ A =jupyter-comm-layer= deals in events which are lists with an identifying
1207+ element in the head position. Jupyter messages are then just one kind of
1208+ event. When events are received, the =jupyter-event-handler= method is called on
1209+ all registered event handlers, passing the event to the handlers. Events can
1210+ be sent to the other end of a =jupyter-comm-layer= using the =jupyter-send= method.
1211+
1212+ Objects interested in receiving events need to define a =jupyter-event-handler=
1213+ method for the particular events they would like to receive. Then, to start
1214+ receiving they should call =jupyter-comm-add-handler= and to
1215+ stop =jupyter-comm-remove-handler=. Here is an example =jupyter-event-handler=
1216+
1217+ #+begin_src elisp
1218+ (cl-defmethod jupyter-event-handler ((client jupyter-kernel-client)
1219+ (event (head message)))
1220+ (cl-destructuring-bind (_ channel _idents . msg) event
1221+ (jupyter-handle-message client channel msg)))
1222+ #+end_src
1223+
1224+ The lifetime of a =jupyter-comm-layer= is controlled by the
1225+ methods =jupyter-comm-start= and =jupyter-comm-start=. To check if
1226+ a =jupyter-comm-layer= is able to send/receive events, use =jupyter-comm-alive-p=.
1227+ Initialization of a =jupyter-comm-layer=, e.g. to ensure the right Jupyter
1228+ session ID/key are used, is done by the optional =jupyter-comm-initialize=
1229+ method.
1230+
11981231** Callbacks and hooks
11991232:PROPERTIES:
12001233:ID: 0E7CA280-8D14-4994-A3C7-C3B7204AC9D2
0 commit comments