Page 1 of 1

cannot trust first beeps

Posted: Tue May 22, 2018 5:49 pm
by dunbarx
This has been going on forever.

In a button script:

Code: Select all

on mouseup
   startTimer
end mouseup

on startTimer
   if the optionKey is down then exit to top
   beep 2
   send "startTimer" to me in 60
end startTimer
Works fine, but each time the process is initiated in a new LC session (and sporadically in an existing session) the very first pair of beeps are delivered much more quickly than all subsequent ones.

Any else seen this? It could be a problem, I suppose, in certain circumstances

Craig

Re: cannot trust first beeps

Posted: Tue May 22, 2018 6:23 pm
by FourthWorld
Timers are sent when idle happens; processing queues may stall a timer in a single-thread program like LC, causing them to batch up and fire more rapidly than expected.

To prevent that I usually check for existing instances of a given timer message before queuing more, e.g.:

Code: Select all

on startTimer
   if the optionKey is down then exit to top
   if "startTimer" is not in the pendingMessages then
      beep 2
      send "startTimer" to me in 60
   end if
end startTimer

Re: cannot trust first beeps

Posted: Tue May 22, 2018 7:19 pm
by dunbarx
Richard.

Makes sense. Thanks.

Craig