forked from emacs-jupyter/jupyter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jupyter-ioloop-comm.el
66 lines (49 loc) · 2.45 KB
/
jupyter-ioloop-comm.el
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
55
56
57
58
59
60
61
62
63
64
65
66
;;; jupyter-ioloop-comm.el --- Communication layer using jupyter-ioloop -*- lexical-binding: t -*-
;; Copyright (C) 2019-2020 Nathaniel Nicandro
;; Author: Nathaniel Nicandro <[email protected]>
;; Created: 27 Jun 2019
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Implement the `jupyter-comm-layer' interface on-top of a `jupyter-ioloop'.
;; Note this class only implements a subset of the `jupyter-comm-layer'
;; interface needed for a `jupyter-kernel-client' and is usually sub-classed to
;; be usable by a `jupyter-kernel-client'. See `jupyter-channel-ioloop-comm'.
;;; Code:
(require 'jupyter-comm-layer)
(require 'jupyter-ioloop)
(defclass jupyter-ioloop-comm (jupyter-comm-layer)
((ioloop :type jupyter-ioloop))
:abstract t)
;; Fall back method that catches IOLoop events that have not been handled by
;; the communication layer already.
(cl-defmethod jupyter-ioloop-handler ((_ioloop jupyter-ioloop)
(comm jupyter-ioloop-comm)
event)
(unless (memq (car event) '(start quit))
(jupyter-event-handler comm event)))
(cl-defmethod jupyter-send ((comm jupyter-ioloop-comm) &rest event)
(apply #'jupyter-send (oref comm ioloop) event))
(cl-defmethod jupyter-comm-start ((comm jupyter-ioloop-comm))
(with-slots (ioloop) comm
(unless (jupyter-ioloop-alive-p ioloop)
(jupyter-ioloop-start ioloop comm))))
(cl-defmethod jupyter-comm-stop ((comm jupyter-ioloop-comm))
(with-slots (ioloop) comm
(when (jupyter-ioloop-alive-p ioloop)
(jupyter-ioloop-stop ioloop))))
(cl-defmethod jupyter-comm-alive-p ((comm jupyter-ioloop-comm))
(and (slot-boundp comm 'ioloop)
(jupyter-ioloop-alive-p (oref comm ioloop))))
(provide 'jupyter-ioloop-comm)
;;; jupyter-ioloop-comm.el ends here