Function: nrepl-send-sync-request
nrepl-send-sync-request is a byte-compiled function defined in
nrepl-client.el.
Signature
(nrepl-send-sync-request REQUEST CONNECTION &optional ABORT-ON-INPUT TOOLING CALLBACK)
Documentation
Send REQUEST to the nREPL server synchronously using CONNECTION.
Hold till final "done" message has arrived and join all response messages of the same "op" that came along. If ABORT-ON-INPUT is non-nil, the function will return nil at the first sign of user input, so as not to hang the interface. If TOOLING, use the tooling session rather than the standard session.
If CALLBACK is non-nil, it will additionally be called on all received
messages. This shouldn't be used this for any control logic — use the
asynchronous nrepl-send-request directly for that. CALLBACK here should
be used to react to some intermediate events in an otherwise synchronous
command and e.g. notify the user about them.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
(defun nrepl-send-sync-request (request connection &optional abort-on-input
tooling callback)
"Send REQUEST to the nREPL server synchronously using CONNECTION.
Hold till final \"done\" message has arrived and join all response messages
of the same \"op\" that came along.
If ABORT-ON-INPUT is non-nil, the function will return nil at the first
sign of user input, so as not to hang the interface.
If TOOLING, use the tooling session rather than the standard session.
If CALLBACK is non-nil, it will additionally be called on all received
messages. This shouldn't be used this for any control logic — use the
asynchronous `nrepl-send-request' directly for that. CALLBACK here should
be used to react to some intermediate events in an otherwise synchronous
command and e.g. notify the user about them."
(let* ((time0 (current-time))
(response (cons 'dict nil))
(nrepl-ongoing-sync-request t)
(cb (lambda (resp)
;; If caller has provided `callback', call it on the response.
(when callback
(funcall callback resp))
(nrepl--merge response resp)))
status)
(nrepl-send-request request cb connection tooling)
(while (and (not (member "done" status))
(not (and abort-on-input
(input-pending-p))))
(setq status (nrepl-dict-get response "status"))
;; If we get a need-input message then the repl probably isn't going
;; anywhere, and we'll just timeout. So we forward it to the user.
(if (member "need-input" status)
(progn (cider-need-input (current-buffer))
;; If the user took a few seconds to respond, we might
;; unnecessarily timeout, so let's reset the timer.
(setq time0 (current-time)))
;; break out in case we don't receive a response for a while
(when (and nrepl-sync-request-timeout
(time-less-p
nrepl-sync-request-timeout
(time-subtract nil time0)))
(error "Sync nREPL request timed out %s after %s secs" request nrepl-sync-request-timeout)))
;; Clean up the response, otherwise we might repeatedly ask for input.
(nrepl-dict-put response "status" (remove "need-input" status))
(accept-process-output nil 0.01))
;; If we couldn't finish, return nil.
(when (member "done" status)
(nrepl-dbind-response response (ex err eval-error pp-stacktrace id)
(when (and ex err)
(cond (eval-error (funcall nrepl-err-handler))
(pp-stacktrace (cider--render-stacktrace-causes
pp-stacktrace (remove "done" status))))) ;; send the error type
(when id
(with-current-buffer connection
(nrepl--mark-id-completed id)))
response))))