unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Filipp Gunbin <fgunbin@fastmail.fm>
To: Rudolf Schlatte <rudi@constantly.at>
Cc: emacs-devel@gnu.org
Subject: Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I find it?
Date: Fri, 12 Nov 2021 17:12:24 +0300	[thread overview]
Message-ID: <m2k0hd31kn.fsf@fastmail.fm> (raw)
In-Reply-To: <m2k0hdsejn.fsf@constantly.at> (Rudolf Schlatte's message of "Fri, 12 Nov 2021 14:13:00 +0100")

On 12/11/2021 14:13 +0100, Rudolf Schlatte wrote:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Óscar Fuentes <ofv@wanadoo.es> writes:
>>
>>> An implementation would be
>>>
>>> (defun timer-active-p (timer)
>>>   (timer--check timer)
>>>   (or (memq timer timer-list))
>>>       (memq timer timer-idle-list))
>>
>> Sounds useful to me.
>
> Of course, the form
>
> (when (timer-active-p my-timer)
>   (do-something-that-errors-when-timer-inactive my-timer))
>
> can still throw an error, since the return value of `timer-active-p' is
> outdated as soon as the function returns..  (Or can timers only fire
> when Emacs is otherwise idle?)

From (elisp) Timers:

--8<---------------cut here---------------start------------->8---
   Emacs cannot run timers at any arbitrary point in a Lisp program; it
can run them only when Emacs could accept output from a subprocess:
namely, while waiting or inside certain primitive functions such as
‘sit-for’ or ‘read-event’ which _can_ wait.  Therefore, a timer’s
execution may be delayed if Emacs is busy.  However, the time of
execution is very precise if Emacs is idle.
--8<---------------cut here---------------end--------------->8---

So it depends on what do-something-that-errors-when-timer-inactive does.



      reply	other threads:[~2021-11-12 14:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 20:31 Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Alan Mackenzie
2021-11-11 20:37 ` Eli Zaretskii
2021-11-11 21:08   ` Alan Mackenzie
2021-11-11 21:24     ` Óscar Fuentes
2021-11-12  2:49       ` Lars Ingebrigtsen
2021-11-12  7:55         ` ๊Unsubscribe Sakesun Roykiattisak
2021-11-12 13:13         ` Why doesn't Emacs have an `active-timer-p' command, or why can't I find it? Rudolf Schlatte
2021-11-12 14:12           ` Filipp Gunbin [this message]

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2k0hd31kn.fsf@fastmail.fm \
    --to=fgunbin@fastmail.fm \
    --cc=emacs-devel@gnu.org \
    --cc=rudi@constantly.at \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).