Created Feb 24, 2026Updated Mar 20, 2026Aleksandr SidunSuggest Edit

Scheduling Tasks with hiRegTimer()

1. How to use hiRegTimer()

The hiRegTimer() function takes two arguments - a function to run (provided as a string) and a number representing tenths of seconds after which the function should run.

Example:

1procedure( func() 2printf("Hello\n") 3) 4 5hiRegTimer("func()" 100)

In this example, we register func() to run after 10 seconds.


Example of running hiRegTimer() function in CIW

Example of running hiRegTimer() function in CIW

Note: Scheduled tasks will run in the current Virtuoso session. If you reopen Virtuoso, tasks from the previous session will be removed.

2. Repeating tasks

To repeat a task, we’ll need to run hiRegTimer() again. To do so, we can create a simple recursion, like this:

1procedure( func() 2printf("Hello\n") 3) 4 5procedure( repeatTask(function) 6let( (repeatCommand) 7 8sprintf(repeatCommand "%s repeatTask(\\"%s\\")" function function) 9hiRegTimer(repeatCommand 100) 10);let 11);procedure

Here, the first argument of hiRegTimer() is modified to include a recursive call to repeatTask(). In the example above, the repeatCommand variable will contain “func() repeatCommand(\”func()\”)”.

Tip: To stop the function from repeating, simply redefine repeatTask() to do nothing.

1procedure( repeatTask(function) 2nil 3)

3. Practical example

Let’s implement a wrapper function to schedule a task at a specific time and optionally repeat it daily.

1procedure( sayHello() 2printf("Hello\n") 3) 4 5 6procedure( scheduleTask(function scheduleTime @key (everyDay nil)) 7/* 8Schedules a task to be executed at a specified time, optionally 9repeating every day. 10 11@param function string 12The name of the SKILL function to be executed at the scheduled time. 13 14@param scheduleTime string 15The target time in the format "HH:MM:SS" at which the function should 16be executed. 17 18@param everyDay boolean 19An optional parameter indicating whether the task should be scheduled 20to repeat every day. Defaults to 'nil'. 21*/ 22let( (secondsLeft scheduleFunction) 23 24secondsLeft = getSecondsLeft(scheduleTime) 25scheduleFunction = function 26when( everyDay 27sprintf(scheduleFunction "%s scheduleTask(\\"%s\\")" function function) 28);when 29 30hiRegTimer(scheduleFunction secondsLeft*10) 31);let 32);procedure 33 34 35procedure( getSecondsLeft(otherTime) 36/* 37Calculates the number of seconds remaining until a specified time on 38the current or next day. 39 40@param otherTime string 41The target time in the format "HH:MM:SS" for which the remaining 42seconds are to be calculated. 43 44@return integer 45Returns the number of seconds left until the specified time. If the 46time has already passed today, it calculates the seconds remaining 47until the same time on the next day. 48*/ 49let( (monthsTable dateTime day month year otherDateTime secondsLeft 50 maxDaysInMonth) 51 52monthsTable = getMonthsTable() 53 54dateTime = timeToTm(stringToTime(getCurrentTime())) 55day = dateTime~>tm_mday 56month = monthsTable[dateTime~>tm_mon+1] 57year = dateTime~>tm_year + 1900 58sprintf(otherDateTime "%s %d %s %d" month day otherTime year) 59 60secondsLeft = compareTime(otherDateTime getCurrentTime()) 61when( secondsLeft <= 0 62; Consider the next day 63maxDaysInMonth = getMonthDaysNumber(month) 64when( month == "Feb" && mod(year 4) != 0 65maxDaysInMonth = 28 66);when 67 68day += 1 69when( day > maxDaysInMonth 70; Next month 71day = 1 72month = monthsTable[dateTime~>tm_mon+2] 73unless( month;13th month doesn't exists 74; Next year 75month = monthsTable[1] 76year += 1 77);unless 78);when 79 80sprintf(otherDateTime "%s %d %s %d" month day otherTime year) 81 82secondsLeft = compareTime(otherDateTime getCurrentTime()) 83);when 84 85secondsLeft 86);let 87);procedure 88 89 90procedure( getMonthsTable() 91/* 92Gets a table mapping month numbers to their corresponding three-letter 93abbreviations. 94 95@return table 96Returns a table where each key is a month number (1 through 12), and 97each value is the corresponding three-letter abbreviation of the month 98name. 99*/ 100let( (monthsTable) 101 102monthsTable = makeTable('monthsTable nil) 103monthsTable[1] = "Jan" 104monthsTable[2] = "Feb" 105monthsTable[3] = "Mar" 106monthsTable[4] = "Apr" 107monthsTable[5] = "May" 108monthsTable[6] = "Jun" 109monthsTable[7] = "Jul" 110monthsTable[8] = "Aug" 111monthsTable[9] = "Sep" 112monthsTable[10] = "Oct" 113monthsTable[11] = "Nov" 114monthsTable[12] = "Dec" 115 116monthsTable 117);let 118);procedure 119 120 121procedure( getMonthDaysNumber(month) 122/* 123Returns the number of days in a given month, accounting for leap years 124in February. 125 126@param month string 127The three-letter abbreviation of the month name. 128 129@return integer 130Returns the maximum number of days in the specified month. February 131is assumed to have 29 days to account for leap years. 132*/ 133let( (maxDays) 134cond( 135( month == "Feb" 136maxDays = 29 137) 138( or(month == "Apr" month == "Jun" month == "Sep" month == "Nov") 139maxDays = 30 140) 141( or(month == "Jan" month == "Mar" month == "May" month == "Jul" 142month == "Aug" month == "Oct" month == "Dec") 143maxDays = 31 144) 145);cond 146 147 148maxDays 149 150);let 151);procedure

Here, our function schedules a provided function at a specific time. If the specified time is already passed, it will schedule for the same time on the next day.

Helper functions:

  • getSecondsLeft(): Calculates seconds remaining until a specified time. It does the comparison between current time and the target date (today or tomorrow).
  • getMonthsTable(): Maps month numbers to three-letter abbreviations.
  • getMonthDaysNumber(): Returns the number of days in a given month, accounting for leap years.

To schedule a task once, run:

1scheduleTask("sayHello()" "16:55:00")

To repeat it every day:

1scheduleTask("sayHello()" "16:55:00" ?everyDay t)

4. Understanding SKILL’s tm structure

SKILL’s tm structure requires a bit of clarification:

1dateTime = timeToTm(stringToTime(getCurrentTime()))

The tm structure holds info about the time and date.


tm structure’s parameters and values

tm structure’s parameters and values

However, month and year parameters are not straightforward:

  • Month representation is from 0 to 11 - For example, in case of May, it will show a number of 4. So, in your SKILL code you’ll have to consider that and to add 1 to the month’s number:
1dateTime~>tm_mon + 1
  • Year representation starts from 1900 - For example, in the year of 2025, it will show a number of 125. So, you’ll always need to add 1900 to it:
1dateTime~>tm_year + 1900

5. More tips

  • You should take care not to schedule anything that is too lengthy to run, since this will appear to occasionally freeze the user interface as the scheduled task runs.
  • It’s hard to keep track of which functions are registered to run in intervals. So try not scheduling many.
  • You may check Cadence’s examples of using the hiRegTimer() function. Start with this one: Cadence hiRegTimer() Example

6. Conclusion

By leveraging hiRegTimer(), you can automate routine tasks and optimize your workflow. Explore its capabilities and see how it can enhance your project efficiency.

Author: Eugeny Khanchin

Comments