* run-with-idle-timer vs. run-at-time
@ 2021-02-15 19:12 Stefan Möding
2021-02-15 19:33 ` Óscar Fuentes
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Möding @ 2021-02-15 19:12 UTC (permalink / raw)
To: help-gnu-emacs
Hi!
I'm trying to understand the difference between these two timers:
(run-with-idle-timer 0 nil (lambda () (...)))
(run-at-time 0 nil (lambda () (...)))
I suspect there is a difference (see below) but I'm unable to come up with
an example where it actually makes a difference. Does anybody have an idea
what condition could cause a different behavior?
I can see from the documentation that `run-with-idle-timer' runs when
Emacs is waiting for input. But that also seems to be the case for
`run-at-time'. Is there a way that `run-at-time' might run at a time
(earlier) when `run-with-idle-timer' would not?
Background:
I'm trying to use the `guess-language' package from MELPA (also see
https://github.com/tmalsburg/guess-language.el). The package integrates
with flyspell to guess the language of the current paragraph and set the
spelling dictionary according to the language. The package maintainer has
implemented this asynchronously using the `run-at-time` function as
illustrated above.
In my setup certain buffers now cause a freeze and I have to C-g to get
back to work. It's reproducible but due to my setup it's too complicated
to expect the package author to have a look (e.g. using
`gnus-dired-attach' to create a message buffer to send a file as
attachment will cause the freeze; flyspell is enabled for message-mode).
I suspect the timer triggers the code to early and Emacs hangs while
trying to talk to the `hunspell' process.
There doesn't seem to be any more blocking if I replace `run-at-time` with
`run-with-idle-timer' in the package code. So there seems to be
a difference. Now I'm trying to come up with an example that might help
the package maintainer to understand why `run-with-idle-timer' might be
a better alternative (if it is that way).
Thanks for any pointers!
--
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: run-with-idle-timer vs. run-at-time
2021-02-15 19:12 run-with-idle-timer vs. run-at-time Stefan Möding
@ 2021-02-15 19:33 ` Óscar Fuentes
2021-02-16 6:50 ` Stefan Möding
0 siblings, 1 reply; 3+ messages in thread
From: Óscar Fuentes @ 2021-02-15 19:33 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Möding <s.moeding@gmail.com> writes:
> I'm trying to understand the difference between these two timers:
>
> (run-with-idle-timer 0 nil (lambda () (...)))
>
> (run-at-time 0 nil (lambda () (...)))
>
> I suspect there is a difference (see below) but I'm unable to come up with
> an example where it actually makes a difference. Does anybody have an idea
> what condition could cause a different behavior?
>
> I can see from the documentation that `run-with-idle-timer' runs when
> Emacs is waiting for input. But that also seems to be the case for
> `run-at-time'. Is there a way that `run-at-time' might run at a time
> (earlier) when `run-with-idle-timer' would not?
Put this code in *scratch*, evaluate it and look at the contents of
*Messages*:
(progn
(sleep-for 1)
(run-at-time 0 nil 'message "running at time")
(run-with-idle-timer 0 nil 'message "running at idle time")
(sleep-for 1)
(message "after run at time")
(message ""))
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: run-with-idle-timer vs. run-at-time
2021-02-15 19:33 ` Óscar Fuentes
@ 2021-02-16 6:50 ` Stefan Möding
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Möding @ 2021-02-16 6:50 UTC (permalink / raw)
To: help-gnu-emacs
Óscar Fuentes <ofv@wanadoo.es> writes:
> (progn
> (sleep-for 1)
> (run-at-time 0 nil 'message "running at time")
> (run-with-idle-timer 0 nil 'message "running at idle time")
> (sleep-for 1)
> (message "after run at time")
> (message ""))
Thank you! Now it makes sense!
Interesting: With (sleep-for 0) both timer are executed after the block.
But with (sit-for 0) the output of the run-at-time is also interleaved.
According to the docs (redisplay) is the same as (sit-for 0) and indeed
this behaves the same.
This could be the root cause for my problem. Some code in the mode hook
runs (redisplay) or (sit-for 0) leading to a premature execution of the
timer.
Very helpful! Thanks again!
--
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-16 6:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-15 19:12 run-with-idle-timer vs. run-at-time Stefan Möding
2021-02-15 19:33 ` Óscar Fuentes
2021-02-16 6:50 ` Stefan Möding
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).