From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: jsonrpc.el closer to merging Date: Mon, 11 Jun 2018 23:26:34 +0100 Message-ID: <874li9559h.fsf@gmail.com> References: <87sh5uvdnr.fsf@gmail.com> <87k1r6uv3p.fsf@gmail.com> <6733499b-b27f-0886-2e8d-bb59c59ace74@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1528755890 27130 195.159.176.226 (11 Jun 2018 22:24:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Jun 2018 22:24:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel To: =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 12 00:24:46 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fSVEz-0006ug-K0 for ged-emacs-devel@m.gmane.org; Tue, 12 Jun 2018 00:24:45 +0200 Original-Received: from localhost ([::1]:51691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSVH4-0001G5-Sk for ged-emacs-devel@m.gmane.org; Mon, 11 Jun 2018 18:26:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSVGv-0001Fx-Ie for emacs-devel@gnu.org; Mon, 11 Jun 2018 18:26:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSVGs-0001SO-CQ for emacs-devel@gnu.org; Mon, 11 Jun 2018 18:26:45 -0400 Original-Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:42310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSVGs-0001RM-4A for emacs-devel@gnu.org; Mon, 11 Jun 2018 18:26:42 -0400 Original-Received: by mail-wr0-x235.google.com with SMTP id w10-v6so21991283wrk.9 for ; Mon, 11 Jun 2018 15:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=lOF+391diSyBvecC1hmxw+KxwJjEs0XKPt5fYcBLQYY=; b=uN6uqKahgEoh8I7JRCin/DDP/M2I8i1ZNowj+u5+b9Ckk8Yl6GUHWPzvZWbUKY3ZMT g5l48KpO4Gv81HqFG9Vh+SPcxDUcpoBbVhr859x1qGGcjTul04YmLCpnu3ChKqbsuqRt pMoVshlphEWUXre5ffLGXHtAzgHBhi38lWWhOnd7yFRxb5BD+aiXS9oYQUWzzRC7B0eS 4snCCTP4nIaU3rDRvA1EGYkM3NSOD7rdZSXlAUSXFLcXnHIY5R+aSNaU+ywWu5xIwb+i w7mdD0Nv4wMNzWh5anEiv6J7zpUDU+XOdR7GDCt6IecdqlJwUwdF468pIp20iARHmx3n Lk+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=lOF+391diSyBvecC1hmxw+KxwJjEs0XKPt5fYcBLQYY=; b=jdgnMpjXMVussq9gifSwF0hyYFp5E7a2u4lPTbhc855XAxN2o71M5B70jpDuliXzYF txFuIXNFqSCx+2aik9gz1E+HrpV3YT/U68JqNPIyEcBwc+Lo6HPRt5YUNMVBADIVuGgC CLZpauwbTOuuwFK4Blj2I5ByLCE2j18oVJUsV3YyfSMt0MJ7FEU6v+d1StXMIedra6nc Ii8qV30/6gGgtwi6SDR1SPZcKnmO8wVmAEA3LT/4C5K2uXTfnYTq5rQly+FaYK7WWeTC DIUR0TBAN9EsR3Kv/+TU3YPx1He+wG8sGB5Lkhp0Mo36nhpld1tRCo5IuR4HOw2mJSmt fo2g== X-Gm-Message-State: APt69E3P0hTs84qc+0tzon95MDIPGfXlLz3HWRBS3WdxqV076rgdJy90 giyh0NleKv/ENus/QQV+3DuHSuNI X-Google-Smtp-Source: ADUXVKKMv6UH5dLVdQyVaas+7huETTF2qX1LWmrwr5BkXT86SveAU1q11Je38GZZJg+spwevidIHSQ== X-Received: by 2002:adf:de82:: with SMTP id w2-v6mr741485wrl.88.1528756000536; Mon, 11 Jun 2018 15:26:40 -0700 (PDT) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id u11-v6sm10712267wrq.68.2018.06.11.15.26.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 15:26:39 -0700 (PDT) In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora=22's?= message of "Mon, 11 Jun 2018 15:42:35 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::235 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:226240 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > Thanks. The context is that I'm trying to see what I need to change to u= se your library. > I have code in which the server responds with progress information as it= processes a query. For example > > -> (id=3Dxyz) Compute \pi to 15 decimals > <- (id=3Dxyz, progress) 10% done > <- (id=3Dxyz, progress) 60% done > <- (id=3Dxyz, response) 3.141592653589793 > > The same lambda gets invoked three times, twice with 'progress and a mes= sage, and once with 'done and a number. > Is there a way to model this is json-rpc.el? >=20=20 > 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=20 > 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 (=3D 42 (jsonrpc-request conn '+ [40 2]))) (should (=3D 42 (jsonrpc-request conn '+ [40 2] :jsonrpc "2.0-EMACS"))) (should (let ((counter 0)) (=3D 42 (jsonrpc-request conn '+ [40 2] :jsonrpc "2.0-EMACS" :partial-handler (lambda (partial) (should (=3D (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 (=3D result 42)) (throw 'done nil)) (when partial (should (null result)) (should (=3D (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))))))