From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#14820: 24.3; elisp manual: How to write good idle timer worker functions? Date: Wed, 26 Jan 2022 18:41:41 +0100 Message-ID: <878rv2pf6y.fsf@gnus.org> References: <51DABDE6.10904@orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38250"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 14820@debbugs.gnu.org To: Phil Sainty Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 26 19:16:49 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCmqe-0009ft-Ud for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Jan 2022 19:16:48 +0100 Original-Received: from localhost ([::1]:50996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCmqd-0004Jy-OM for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Jan 2022 13:16:47 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCmJ1-0002Ue-7N for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 12:42:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60498) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nCmJ0-00066D-EP for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 12:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nCmJ0-0000Uu-DO for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 12:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Jan 2022 17:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14820 X-GNU-PR-Package: emacs Original-Received: via spool by 14820-submit@debbugs.gnu.org id=B14820.16432189131884 (code B ref 14820); Wed, 26 Jan 2022 17:42:02 +0000 Original-Received: (at 14820) by debbugs.gnu.org; 26 Jan 2022 17:41:53 +0000 Original-Received: from localhost ([127.0.0.1]:53398 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCmIr-0000UI-GW for submit@debbugs.gnu.org; Wed, 26 Jan 2022 12:41:53 -0500 Original-Received: from quimby.gnus.org ([95.216.78.240]:50296) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCmIo-0000Ty-Uf for 14820@debbugs.gnu.org; Wed, 26 Jan 2022 12:41:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=J1Wad6Na9NqFHwxtiyJIiwfAKU8pIZb2XuKlArBdVn0=; b=JxrOk2P37sfLAdqwEheLEypJDU sHdoUXAUY1lR2g8lFrTEl/nAP1G0uxeP3RspAxUsVllYIqWse2oVSFOgwLzWdP8bgBTAgQqFxqlQR EUtVd0Qes07kzb+XPhm2QRGJpoBofa5CNclknqw+LEFew59tmwXIgL5vVU9Aoh36XA8E=; Original-Received: from [84.212.220.105] (helo=giant) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCmIf-0004PE-Pd; Wed, 26 Jan 2022 18:41:44 +0100 X-Now-Playing: Nina Simone's _Little Girl Blue_: "Good Bait" In-Reply-To: <51DABDE6.10904@orcon.net.nz> (Phil Sainty's message of "Tue, 09 Jul 2013 01:25:58 +1200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:225307 Archived-At: Phil Sainty writes: > There is a substantial amount of work to perform 'in the background', > taking (in total) in excess of 10 seconds to complete, and also > needing to be run on a semi-regular basis, so making the user wait > each time is out of the question. I wish to perform the work in idle > time, as quickly as possible, but without disrupting the user. > > The work can be broken down into a queue of small items, each of which > takes a fraction of a second to complete. [...] > The quote above indicates that `input-pending-p' is not sufficient to > detect all kinds of pending activity, but it doesn't suggest other > options. (I'm going through old bug reports that unfortunately weren't resolved at the time.) I think that these days, you'd probably implement this using Emacs threads, but I think the general advice in that node is still sound -- if you're doing something that takes a long time from an idle hook, you should instead schedule a new idle timer (with a very short timeout) instead of trying to use `pending-input-p' and `sit-for'. So I'm not sure whether there's anything more to do in this bug report? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no