summaryrefslogtreecommitdiff
path: root/elisp/geiser-connection.el
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-12-27 16:55:43 +0000
committerjao <jao@gnu.org>2021-12-27 16:56:30 +0000
commitf5e7004bf2f5af381dbf3387108cde210a190733 (patch)
treed934e5bbcb267e0cd84a132677401219f2b7ce77 /elisp/geiser-connection.el
parent48e6a6671571ef60ae764b165a2f152fc6d9e227 (diff)
downloadgeiser-f5e7004bf2f5af381dbf3387108cde210a190733.tar.gz
geiser-f5e7004bf2f5af381dbf3387108cde210a190733.tar.bz2
New helper, geiser-eval-wait, to facilitate synchronous evaluations
This should address, for instance, issue #30
Diffstat (limited to 'elisp/geiser-connection.el')
-rw-r--r--elisp/geiser-connection.el24
1 files changed, 15 insertions, 9 deletions
diff --git a/elisp/geiser-connection.el b/elisp/geiser-connection.el
index 745aa14..87f5f7f 100644
--- a/elisp/geiser-connection.el
+++ b/elisp/geiser-connection.el
@@ -260,19 +260,25 @@
(when (process-live-p proc)
(interrupt-process proc))))
+(defun geiser-con--wait (req timeout)
+ "Wait for the given request REQ to finish, up to TIMEOUT secs, returning its result."
+ (let* ((con (geiser-con--request-connection req))
+ (id (geiser-con--request-id req))
+ (timeout (/ (or timeout geiser-connection-timeout) 1000.0))
+ (step (/ timeout 10)))
+ (with-timeout (timeout (geiser-con--request-deactivate req))
+ (condition-case nil
+ (while (and (geiser-con--connection-process con)
+ (not (geiser-con--connection-completed-p con id)))
+ (accept-process-output proc step))
+ (error (geiser-con--request-deactivate req))))))
+
(defun geiser-con--send-string/wait (con str cont &optional timeout sbuf)
(save-current-buffer
(let ((proc (and con (geiser-con--connection-process con))))
(unless proc (error "Geiser connection not active"))
- (let* ((req (geiser-con--send-string con str cont sbuf))
- (id (geiser-con--request-id req))
- (timeout (/ (or timeout geiser-connection-timeout) 1000.0)))
- (with-timeout (timeout (geiser-con--request-deactivate req))
- (condition-case nil
- (while (and (geiser-con--connection-process con)
- (not (geiser-con--connection-completed-p con id)))
- (accept-process-output proc (/ timeout 10)))
- (error (geiser-con--request-deactivate req))))))))
+ (let ((req (geiser-con--send-string con str cont sbuf)))
+ (geiser-con--wait req timeout)))))
(provide 'geiser-connection)