Browse Source

Add a hook run when a connection is closed

* indium-v8.el (indium-connection-closed-hook): New hook.
* indium-backend.el: Document the new hook.
* indium-repl.el: Call the new hook.
workspaces
Nicolas Petton 3 years ago
parent
commit
2e516374ec
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
3 changed files with 8 additions and 4 deletions
  1. +3
    -1
      indium-backend.el
  2. +2
    -0
      indium-repl.el
  3. +3
    -3
      indium-v8.el

+ 3
- 1
indium-backend.el View File

@ -112,7 +112,9 @@ The new connection is based on the current (usually closed) one."
t)
(cl-defgeneric indium-backend-close-connection (_backend)
"Close the current connection.")
"Close the current connection.
Concrete implementations should run `indium-connection-closed-hook'.")
(cl-defgeneric indium-backend-reconnect (_backend)
"Try to re-establish a connection.


+ 2
- 0
indium-repl.el View File

@ -445,5 +445,7 @@ Evaluate CALLBACK with the completion candidates."
repl-buffer)))
(setq pos next)))))))
(add-hook 'indium-connection-closed-hook #'indium-repl--handle-connection-closed)
(provide 'indium-repl)
;;; indium-repl.el ends here

+ 3
- 3
indium-v8.el View File

@ -75,7 +75,8 @@
(cl-defmethod indium-backend-close-connection ((_backend (eql v8)))
"Close the websocket associated with the current connection."
(websocket-close (indium-connection-ws indium-current-connection)))
(websocket-close (indium-connection-ws indium-current-connection))
(run-hooks 'indium-connection-closed-hook))
(cl-defmethod indium-backend-reconnect ((_backend (eql v8)))
(let ((url (indium-current-connection-url))
@ -422,8 +423,7 @@ MESSAGE explains why the connection has been closed."
(defun indium-v8--handle-ws-closed (_ws)
"Cleanup function called when the connection socket is closed."
(run-hooks 'indium-connection-closed-hook)
(indium-repl--handle-connection-closed))
(run-hooks 'indium-connection-closed-hook))
(defun indium-v8--handle-ws-error (_ws _action error)
"Display an error message for an exception in a websocket callback handling.


Loading…
Cancel
Save