Separate Timer First-Execution Duration

Propose new features and changes
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Separate Timer First-Execution Duration

Post by Coiler » 29 Mar 2021, 11:19

Currently, you can specify a negative timing value to SetTimer() to request a single execution, and a positive value to request repeated executions. It would be really handy to have a method to request that the first call of a timer to be executed at a different/specific time.

Timers are a great way to separate execution into a different thread in order to avoid locking up hot-key threads for repeating actions. I often initialize my repeating timers with a small negative value to begin, then have the timer callback function update that time to a specific positive rate after the first call.

Something I think would be really useful would be an optional first_call duration parameter to SetTimer(), which relates only to the first execution of the timer callback after SetTimer() is called. I find myself needing to adjust the first execution of timers pretty often. So from my own limited experience with AHK, it seems like this would be a useful feature.

lexikos
Posts: 9611
Joined: 30 Sep 2013, 04:07
Contact:

Re: Separate Timer First-Execution Duration

Post by lexikos » 30 Mar 2021, 03:56

I don't think I'll implement this because:
  • It is extremely trivial to achieve the desired effect already.
  • I don't recall having a need for it myself.
With a single line of v2 code, you can implement a function which supports this (assuming I understand your request correctly).

Code: Select all

#Requires AutoHotkey v2.0-a
SetTimerFirst(() => ToolTip("Tick @ " A_Sec), 2000, 1000)

SetTimerFirst(fn, first, other) => SetTimer(() => (SetTimer(fn, other), fn()), -Abs(first))
It can be done in v1, but I prefer not to write v1 code. ;)

Post Reply

Return to “Wish List”