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: run-with-timer vs run-with-idle-timer Date: Fri, 11 May 2018 11:39:16 +0100 Message-ID: <871seiqxwr.fsf@gmail.com> References: <87tvrgd972.fsf@gmail.com> <87a7t74tsf.fsf@gnuvola.org> <87603v4a5x.fsf@gnuvola.org> 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 1526035079 20155 195.159.176.226 (11 May 2018 10:37:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 May 2018 10:37:59 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 11 12:37:55 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 1fH5Qv-0005A9-S9 for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 12:37:54 +0200 Original-Received: from localhost ([::1]:38124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH5T3-0000wx-07 for ged-emacs-devel@m.gmane.org; Fri, 11 May 2018 06:40:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH5SP-0000vo-Cr for emacs-devel@gnu.org; Fri, 11 May 2018 06:39:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH5SM-00014P-A3 for emacs-devel@gnu.org; Fri, 11 May 2018 06:39:25 -0400 Original-Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:40325) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fH5SM-000148-2T for emacs-devel@gnu.org; Fri, 11 May 2018 06:39:22 -0400 Original-Received: by mail-wm0-x22e.google.com with SMTP id j5-v6so2343215wme.5 for ; Fri, 11 May 2018 03:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-transfer-encoding; bh=1saD00ODxDj+25Oc3h9C4l+9/1pohvS5mnBwID5UsR4=; b=g4uyKi24h5jytvTSHMIoPu9y5KQP59VrU8GVQUG1rwnO072togUC3ji97eVkIR2X6w PnO4hX16IgIEWUk+bE6Qr0FISqj/2UBu8bRqOebjxfVUEkyaBkCC6xveF9WhSn6g+eC3 vjgKT84MJ+YJhsN9NeZXTpqqjLdW/yZPiD06+8tdY+3u6WpLhuUt7biQtf+jWhAunl8J Uiv884i54zXf9EmWP9Tsle2aYGL+2zCuuZivcjAFHn1PWWlOJ3joB2/W8vmuqGu7rV4I 4jCIsMMFqJBSRSW/mzNCY1z+CzMxPgwjk4qfePMIlAKaj72+kgZ+501rZtVDujLTAGN+ NjzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=1saD00ODxDj+25Oc3h9C4l+9/1pohvS5mnBwID5UsR4=; b=cqwY8tY1c2sTmGmM4GbaHMBpJNvTaTTt1X1NmbonmDhKWGgI7F1qH9ctanMnAw0Meg DgJUdGSbzyp3KnlkhoGoZIioN//+jxBpp4ndArNJPn7MOMzLwJBIpUoDk8xb7CTNFUI6 9jaW0IlUfxTfRjnrXQY7/WV3xmh1AnNtkdJbEDeOt2MvGHBYmwo9U9r4Dj89R4gYSnM+ kY0rTReLHaBzcet5H9Ok2D19Hfz9atwNQzJAqo+BJdqlxSFnlK2w9ngs3WRz9BNzmggw UpcnsHYpkLp9H1MCXWuljzhdhwWw1Eq9/zeqOrS1theV/MNkSJ4fRNhXYhsBWTSepnfm yuLg== X-Gm-Message-State: ALKqPwc3Ez9D0yLbs9pzxxjL/z1dijQElaq7tXSVLOiuRD0naLTvs2f1 aL+5Kjp8Ld9vjIAP3yB5pTW8TaKQ X-Google-Smtp-Source: AB8JxZrdu3yFyMGn5wCXMlkMf2iEr6DVgPiKjr1Db46ivefASAuBeAZr2g6y8X1884WtS0DEgCaEKg== X-Received: by 2002:a1c:dca:: with SMTP id 193-v6mr1526964wmn.36.1526035160413; Fri, 11 May 2018 03:39:20 -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 e50-v6sm6530045wre.4.2018.05.11.03.39.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 May 2018 03:39:19 -0700 (PDT) In-Reply-To: <87603v4a5x.fsf@gnuvola.org> (Thien-Thi Nguyen's message of "Thu, 10 May 2018 20:50:50 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22e 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:225226 Archived-At: Thien-Thi Nguyen writes: > If you can structure whatever =E2=80=98catch=E2=80=99es the =E2=80=98thro= w=E2=80=99s to mutate > state visible to CONDITION, then you can use =E2=80=98while CONDITION=E2= =80=99. > If that state is dynamic (e.g., declared w/ =E2=80=98defvar=E2=80=99), yo= u can > can reconfigure the =E2=80=98throw=E2=80=99 to simply mutate it directly,= and > eliminate the =E2=80=98catch=E2=80=99 part (and still use =E2=80=98while = CONDITION=E2=80=99). After thinking a bit about it, you're totally right, and it becomes much simpler (read below). > > I suppose it's a matter of style. Maybe not, maybe yours is indeed more efficient, since it amounts to far fewer calls to accept-process-output. > able to play multiple games simultaneously (i.e., run multiple > independent child processes), and greedily spinning borks that. Since from Emacs's perspective we're both blocking, you must mean that you have less CPU available for the subprocesses, right? > I'd appreciate seeing a skeleton of the code, because what i > imagine it to be is probably not exactly what it is. (I could > be misunderstanding your description grossly.) If you haven't yet connected the dots, this is for my new mode eglot.el from the other thread. Since it is very new, I think I'm just going to apply your suggestion (diff below). It works fine and the code becomes tighter, though it still doesn't solve the original problem that makes the idle-timer not kick in in the meantime. (Later, I can explain more about why I need that, and how I'm working around it). diff --git a/eglot.el b/eglot.el index aabaf54..d8fa8be 100644 --- a/eglot.el +++ b/eglot.el @@ -652,25 +652,20 @@ DEFERRED is passed to `eglot--async-request', which s= ee." ;; bad idea, since that might lead to the request never having a ;; chance to run, because `eglot--ready-predicates'. (when deferred (eglot--signal-textDocument/didChange)) - (let* ((done (make-symbol "eglot--request-catch-tag")) - (res - (catch done (eglot--async-request - proc method params - :success-fn (lambda (&rest args) - (throw done (if (vectorp (car args)) - (car args) args))) - :error-fn (eglot--lambda - (&key code message &allow-other-keys) - (throw done - `(error ,(format "Oops: %s: %s" - code message)))) - :timeout-fn (lambda () - (throw done '(error "Timed out"))) - :deferred deferred) - ;; now spin, baby! - (while t (accept-process-output nil 0.01))))) - (when (and (listp res) (eq 'error (car res))) (eglot--error (cadr res)= )) - res)) + (let (retval) + (eglot--async-request + proc method params + :success-fn (lambda (&rest args) + (setq retval `(done ,(if (vectorp (car args)) + (car args) args)))) + :error-fn (eglot--lambda (&key code message &allow-other-keys) + (setq retval `(error ,(format "Oops: %s: %s" code message= )))) + :timeout-fn (lambda () + (setq retval '(error "Timed out"))) + :deferred deferred) + (while (not retval) (accept-process-output nil 30)) + (when (eq 'error (car retval)) (eglot--error (cadr retval))) + (cadr retval))) =20 (cl-defun eglot--notify (process method params) "Notify PROCESS of something, don't expect a reply.e"