emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why doesn't Emacs have an `active-timer-p' command, or why can't I f


From: Filipp Gunbin
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]