[Top][All Lists]

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

Re: Should `cancel-timer' use `delete' instead of `delq'?

From: Stuart D. Herring
Subject: Re: Should `cancel-timer' use `delete' instead of `delq'?
Date: Tue, 5 Sep 2006 12:13:43 -0700 (PDT)
User-agent: SquirrelMail/1.4.6-7.el3.7lanl

> If, on the other hand, the use of delq in `cancel-timer' is unintentional
> and is not needed, then perhaps delete should be used instead of delq, so
> that all timers with the same parameters are cancelled at once.

Others have talked about the philosophy of timers, but let me point out
that this particular idea wouldn't work anyway.  Evaluate this to see why:

(let ((ts (list (run-with-timer 1.2 1 'ignore)
                (progn (sit-for 0.2) (run-with-timer 1.2 1 'ignore)))))
  (message "%s" ts)
  (prog1 (equal (car ts) (cadr ts))
    (mapcar 'cancel-timer ts)))

Because the precise timing of a timer (especially a repeating one) depends
on when it was created and how much time has since elapsed, the internal
representation of a timer cannot be merely its invocation parameters (and
in fact loses the delay argument, because a timer delayed by 10s started
9s ago looks the same as one delayed by 1s started now).  So "similar"
timers aren't necessarily `equal', and not all timers that are `equal'
were created with a call to `run-with-timer' with the same arguments. 
(Some may have been generated with `timer-create' directly!)  In other
words, we use `eq' because using `equal' doesn't work (although there are
obviously other implementations that could support such a practice).

Perhaps what you want is `cancel-function-timers'?  Certainly for testing
it's quite useful.  You could also just store some "mundane" value of
`timer-list' somewhere and restore it instead of specifically cancelling

Hope this helps,

This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during

reply via email to

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