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: A question regarding sit-for (and while-no-input) Date: Thu, 06 Sep 2018 12:29:26 +0100 Message-ID: <87k1nyzwx5.fsf@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 1536233264 7955 195.159.176.226 (6 Sep 2018 11:27:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Sep 2018 11:27:44 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 06 13:27:40 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 1fxsRo-0001y9-5H for ged-emacs-devel@m.gmane.org; Thu, 06 Sep 2018 13:27:40 +0200 Original-Received: from localhost ([::1]:60871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxsTu-0006KO-BP for ged-emacs-devel@m.gmane.org; Thu, 06 Sep 2018 07:29:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxsTh-0006KG-8w for emacs-devel@gnu.org; Thu, 06 Sep 2018 07:29:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxsTb-00037x-Cl for emacs-devel@gnu.org; Thu, 06 Sep 2018 07:29:37 -0400 Original-Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:35332) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxsTb-00036z-37 for emacs-devel@gnu.org; Thu, 06 Sep 2018 07:29:31 -0400 Original-Received: by mail-wm0-x22c.google.com with SMTP id o18-v6so10905194wmc.0 for ; Thu, 06 Sep 2018 04:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:user-agent:date:message-id:mime-version :content-transfer-encoding; bh=4Clt1r9XFdDzynm18L1xb7/uTjpuTuFKEGmPJdMGKqA=; b=Y61c5L9P7E1+m4ER6WJZmvAhoHWmdZXq3/+EgsZPtSvf7MqT/NltY/qL814h0LLA64 ADrqbVNQsDOuAn4XVXoZfRPOZdXEF1y8OT6t3pw6yRGr0O67gF4SiDh/5w2vQqTu7jsQ F5Pj2wA0t1kznIP3dcCtQOja/svn1jr7LiP5Ckw6izU+KTohQyjt8CCMWUFWzXel97+m g2z4YqTb0SR6cseDi9+GvjFUCwintS1j6NmlMCxU1fGHDHkwaEY7mvVw2vtlYMKyizxW YzXU/dd9Zv3Ay7jKfjWyjZPfMUYPNJ3trFXDx8UZA20x5Pg9yPMbZpmIM6ynkIW30NU2 VMOg== 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:user-agent:date:message-id :mime-version:content-transfer-encoding; bh=4Clt1r9XFdDzynm18L1xb7/uTjpuTuFKEGmPJdMGKqA=; b=R1BAcG7v1oOE3gQa7NaYqSLWP5+7bkK3VOzBy3mew14PaEDpMmdyCSNijJ6U7UcsAu lS9AOsu4PShn78VsXI48JDmiu/yCOE+4tUAlwvsE91VnCqhOf2oCp9cP1Ul05B+8lrkK CRfYhiaSjpfEGzHJrYM8vfpnMPUdye9oo0qqi0aPnDOoVyj2XHsrAXwWdaV0rULMYTfn syIiPRF5lVBMlNf20asfmF06AoNTEhIytM9SMsNok/2HTU0UPTjYsTdelwoES2Gn3twb u9zsIgj0TiybLi6QZFAkaWlDJridionhzrDn8dsA618/sQAWXL8RczXzjFCtQ0l6s3Ej AJXw== X-Gm-Message-State: APzg51BnTKJDvEZ138cq/35J43Se0k072CTCkxKHxsILyipVwAtv3aA4 kGe3+sv3+iuQtgMvrSgWBWmdx8Uj X-Google-Smtp-Source: ANB0VdYCTxn6XeN6KQkUipEiPX6dyvBlwpnDyvQM+p0zuGoeoPDoOmwqdmH82kR8xZ6ZjtOkacsSqQ== X-Received: by 2002:a1c:889:: with SMTP id 131-v6mr1817061wmi.142.1536233369551; Thu, 06 Sep 2018 04:29:29 -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 f13-v6sm5340936wrt.9.2018.09.06.04.29.27 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 04:29:28 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22c 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:229336 Archived-At: Hi, In a couple of my extensions (jsonrpc.el and sly), I am using a technique for synchronously fetching completion candidates from an external process while still maintaining high responsiveness to the user's input. This is very useful for working with company.el, for example. If the user types the first few letters of a completion, the system goes to work immediately fetching candidates. If the candidates don't arrive in time, they are silently discarded. I am running into a bug in my program, which only happens sometimes and is hard to reproduce. I don't know how to fix it. I hope this simplified snippet from the function jsonrpc-request in lisp/jsonrpc.el illustrates the problem sufficiently for someone to provide some hint as to what might be going askew: (let ((tag (some-unique-symbol)) (cancelled nil)) (catch tag ... (lambda (...) (unless cancelled (throw tag result-or-error))) ... (cond (cancel-on-input (while (sit-for 30)) (setq cancelled t) `(cancelled ,cancel-on-input-retval)) (t (while t (accept-process-output nil 30))))) ... ) 'cancel-on-input' is a parameter to jsonrpc-request. If the caller provides it as 't', it means he/she wants that call to block as long as there is no input from the user. A response from the server before that happens, which takes the form of a call to anonymous lambda, will also cause the function to return. Most of the time, this works flawlessly, as intended. But the behaviour I'm witnessing is that (throw tag) sometimes happens after the (catch tag ...) has been torn down. What am I missing?? If the catch has been torn down then surely (setq cancelled t) must have run, right? Otherwise I would be seeing an error from sit-for, which I'm not. Thanks, Jo=C3=A3o