From: "João Távora" <joaotavora@gmail.com>
To: "Clément Pit-Claudel" <cpitclaudel@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: jsonrpc.el closer to merging
Date: Mon, 11 Jun 2018 23:26:34 +0100 [thread overview]
Message-ID: <874li9559h.fsf@gmail.com> (raw)
In-Reply-To: <CALDnm52oFocyGA8uQKkO4BymjCPjZew41GEraRaAU97ev_DzhA@mail.gmail.com> ("João Távora"'s message of "Mon, 11 Jun 2018 15:42:35 +0100")
João Távora <joaotavora@gmail.com> writes:
> Thanks. The context is that I'm trying to see what I need to change to use your library.
> I have code in which the server responds with progress information as it processes a query. For example
>
> -> (id=xyz) Compute \pi to 15 decimals
> <- (id=xyz, progress) 10% done
> <- (id=xyz, progress) 60% done
> <- (id=xyz, response) 3.141592653589793
>
> The same lambda gets invoked three times, twice with 'progress and a message, and once with 'done and a number.
> Is there a way to model this is json-rpc.el?
>
> Hmm, I see. No the library doesn't allow this (and neither does
> JSONRPC, I think)
>
> Why don't you tell me, in pseudo-code, how you would like it to work?
> Perhaps we can add that as a JSONRPC extension (there's a version
> that I'm not using).
I though a bit more about this and your use case seems to be quite
reasonable.
First, when I sand "there's a version", I meant "there's a version
field" that I'm not using, it's usually the string "2.0". But if we *do*
use it, we can set it to something like 2.0-EMACS which means a
backward-compatible extension to the JSONRPC protocol.
In this extension, responses can have a :PARTIAL field, and the endpoint
receiving such a request should expect more responses with that ID until
a final response with the regular :RESULT field comes in.
What do you think?
I implemented this in the 'multi-response-requests' branch of
git@github.com:joaotavora/eglot.
Here's an example usage from the automated tests file jsonrpc-tests.el:
In this fixture the server responds thrice with partials 1 2 and 3
before sending the actual results. You can pass :partial-handler to
jsonrpc-request and it will get called with the partial result (while
the function is still blocking).
Or you can pass a more generic SUCCESS-FN to jsonrpc-async-request.
(ert-deftest partial-replies ()
"Test some basic partial replies."
(jsonrpc--with-emacsrpc-fixture (conn :partial-responses '(1 2 3))
(should-error
(= 42 (jsonrpc-request conn '+ [40 2])))
(should
(= 42 (jsonrpc-request conn '+ [40 2] :jsonrpc "2.0-EMACS")))
(should
(let ((counter 0))
(= 42 (jsonrpc-request
conn '+ [40 2]
:jsonrpc "2.0-EMACS"
:partial-handler (lambda (partial)
(should (= (cl-incf counter) partial)))))))
(catch 'done
(let ((counter 0))
(jsonrpc-async-request conn '+ [40 2] :jsonrpc "2.0-EMACS"
:success-fn
(lambda (result &optional partial)
(when result
(should (null partial))
(should (= result 42))
(throw 'done nil))
(when partial
(should (null result))
(should (= (cl-incf counter) partial)))))
;; Need this so that the test keeps running a little bit
(while (jsonrpc-running-p conn) (accept-process-output nil 3))))))
next prev parent reply other threads:[~2018-06-11 22:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-10 15:56 jsonrpc.el closer to merging João Távora
2018-06-10 17:56 ` Clément Pit-Claudel
2018-06-10 22:36 ` João Távora
2018-06-11 13:08 ` Clément Pit-Claudel
2018-06-11 14:42 ` João Távora
2018-06-11 22:26 ` João Távora [this message]
2018-06-11 23:13 ` Clément Pit-Claudel
2018-06-13 10:19 ` João Távora
2018-06-11 1:46 ` Stefan Monnier
2018-06-11 6:34 ` João Távora
2018-06-11 12:30 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874li9559h.fsf@gmail.com \
--to=joaotavora@gmail.com \
--cc=cpitclaudel@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.