aboutsummaryrefslogtreecommitdiffstats
path: root/l
diff options
context:
space:
mode:
authorTeddy Wing2021-02-14 19:52:32 +0100
committerTeddy Wing2021-02-14 19:52:32 +0100
commit94265081b0efdd13ab480032547d2ac1f76daf83 (patch)
tree315922c0bfefc1cdb24bbcae953ddef2a21d8fc0 /l
parent5baf8d91fc8450cc5e9639fab25a01c432986b7b (diff)
downloadextreload-94265081b0efdd13ab480032547d2ac1f76daf83.tar.bz2
Timeout after five seconds
Set a five second timeout to ensure we don't block endlessly if we send a WebSocket message and don't receive a response in a reasonable amount of time. Chose five seconds arbitrarily, but that seems like more than enough time to do our work. If it takes longer, something else is probably wrong.
Diffstat (limited to 'l')
-rw-r--r--l/extreload.asd1
-rw-r--r--l/src/main.lisp23
2 files changed, 14 insertions, 10 deletions
diff --git a/l/extreload.asd b/l/extreload.asd
index b283481..2748eee 100644
--- a/l/extreload.asd
+++ b/l/extreload.asd
@@ -2,6 +2,7 @@
:version "0.0.1"
:depends-on (:jsown
:sysexits
+ :trivial-timeout
:unix-opts
:wait-group
:websocket-driver-client)
diff --git a/l/src/main.lisp b/l/src/main.lisp
index 641255b..0695f20 100644
--- a/l/src/main.lisp
+++ b/l/src/main.lisp
@@ -6,6 +6,8 @@
(defvar *extension-targets-count* 0)
(defvar *last-session-id* "")
+(defconstant +timeout-seconds+ 5)
+
(opts:define-opts
(:name :socket-url
:description "DevTools protocol WebSocket URL"
@@ -32,18 +34,19 @@
;; Store the WebSocket client as a global.
(defvar *client* (ws-client config))
- (with-websocket-connection (*client*)
- (wsd:on :message *client*
- #'(lambda (message)
- (ws-on-message
- message
- (extension-ids config)
- (reload-current-tab config))))
+ (trivial-timeout:with-timeout (+timeout-seconds+)
+ (with-websocket-connection (*client*)
+ (wsd:on :message *client*
+ #'(lambda (message)
+ (ws-on-message
+ message
+ (extension-ids config)
+ (reload-current-tab config))))
- (websocket-send *client* (target-get-targets-msg
- (next-call-id *devtools-root-call-id*)))
+ (websocket-send *client* (target-get-targets-msg
+ (next-call-id *devtools-root-call-id*)))
- (wait-group:wait *wg*)))))
+ (wait-group:wait *wg*))))))
(defun ws-on-message (message extension-ids reload-current-tab)
(let* ((response (jsown:parse message))