Function: jsonrpc--async-request-1
jsonrpc--async-request-1 is a byte-compiled function defined in
jsonrpc.el.gz.
Signature
(jsonrpc--async-request-1 CONNECTION METHOD PARAMS &rest ARGS &key SUCCESS-FN ERROR-FN TIMEOUT-FN (TIMEOUT jsonrpc-default-request-timeout) (DEFERRED nil))
Documentation
Does actual work for jsonrpc-async-request.
Return a list (ID TIMER). ID is the new request's ID, or nil if the request was deferred. TIMER is a timer object set (or nil, if TIMEOUT is nil).
Source Code
;; Defined in /usr/src/emacs/lisp/jsonrpc.el.gz
(cl-defun jsonrpc--async-request-1 (connection
method
params
&rest args
&key success-fn error-fn timeout-fn
(timeout jsonrpc-default-request-timeout)
(deferred nil))
"Does actual work for `jsonrpc-async-request'.
Return a list (ID TIMER). ID is the new request's ID, or nil if
the request was deferred. TIMER is a timer object set (or nil, if
TIMEOUT is nil)."
(pcase-let* ((buf (current-buffer)) (point (point))
(`(,_ ,timer ,old-id)
(and deferred (gethash (list deferred buf)
(jsonrpc--deferred-actions connection))))
(id (or old-id (cl-incf (jsonrpc--next-request-id connection))))
(make-timer
(lambda ( )
(when timeout
(run-with-timer
timeout nil
(lambda ()
(remhash id (jsonrpc--request-continuations connection))
(remhash (list deferred buf)
(jsonrpc--deferred-actions connection))
(if timeout-fn (funcall timeout-fn)
(jsonrpc--debug
connection `(:timed-out ,method :id ,id
:params ,params)))))))))
(when deferred
(if (jsonrpc-connection-ready-p connection deferred)
;; Server is ready, we jump below and send it immediately.
(remhash (list deferred buf) (jsonrpc--deferred-actions connection))
;; Otherwise, save in `jsonrpc--deferred-actions' and exit non-locally
(unless old-id
(jsonrpc--debug connection `(:deferring ,method :id ,id :params
,params)))
(puthash (list deferred buf)
(list (lambda ()
(when (buffer-live-p buf)
(with-current-buffer buf
(save-excursion (goto-char point)
(apply #'jsonrpc-async-request
connection
method params args)))))
(or timer (setq timer (funcall make-timer))) id)
(jsonrpc--deferred-actions connection))
(cl-return-from jsonrpc--async-request-1 (list id timer))))
;; Really send it
;;
(jsonrpc-connection-send connection
:id id
:method method
:params params)
(puthash id
(list (or success-fn
(jsonrpc-lambda (&rest _ignored)
(jsonrpc--debug
connection (list :message "success ignored"
:id id))))
(or error-fn
(jsonrpc-lambda (&key code message &allow-other-keys)
(jsonrpc--debug
connection (list
:message
(format "error ignored, status set (%s)"
message)
:id id :error code))))
(setq timer (funcall make-timer)))
(jsonrpc--request-continuations connection))
(list id timer)))