timer(n)
๐ timer(n) โ Tcl Built-In Commands, but make it cute
okay bestie, welcome to timer(n), the Tcl built-in that handles timer events for monotonic and wall clock time โจ. It's giving "I schedule things and I also make you wait" energy, and honestly? Iconic.
๐ธ NAME ๐ธ
timer โ timer events for monotonic and wall clock time. that's the whole vibe. ๐ฐ๏ธ
โจ SYNOPSIS โจ
timer in delay unit script
timer at timepoint unit script
timer idle script
timer sleep for delay ?unit?
timer sleep until timepoint ?unit?
timer cancel id
timer info ?id?
seven forms, seven little moods. slay. ๐
๐ฆ DESCRIPTION ๐ฆ
so like, this command is here to delay execution of your program or to run a command in the background sometime in the future ๐ซถ. time can be specified two ways, bestie: by a monotonic time delay, or by a wall clock time point. and it has the following methods, presented in order because we're not chaotic (we are, but we're pretending) ๐
๐ง timer in delay unit script
okay so in this form the command returns immediately โ like, it does not wait around, it has places to be โ but it arranges for a Tcl command to be executed after the given monotonic time delay has elapsed, as an event handler โณ. the delay value is given in the specified unit โ peep TIME UNITS below for the available units ๐.
the command will be executed exactly once, after the given time delay. the delayed command is given by the argument script. and heads up: it gets executed at global level (outside the context of any Tcl procedure) โ no hiding in locals, bestie ๐.
if an error occurs while executing the delayed command, then the background error will be reported by the command registered with interp bgerror ๐ญ.
the command returns an identifier that you can use to cancel the delayed command with timer cancel or after cancel ๐ซ. keep it safe!
adelayvalue of0(or negative) queues the event immediately with priority over other event types โ unless it's installed with an event proc, in which case it'll wait for the next round of events ๐.
also, fun fact: the command after ms script may also be used to register monotonic clock timer events. they are handled by the same queue as this form of the timer command ๐ฅ one queue, one family, no cap.
๐ timer at timepoint unit script
same as timer in, but you're specifying a wall clock time point (epoc) instead ๐๏ธ. a typical use-case is to pass the result of a clock scan as the time point โ see the example below, iykyk ๐.
wall clock events have second priority after monotonic clock events ๐. if both fire the same instant, the monotonic clock command is always handled first. them's the rules.
๐ timer idle script
this one arranges for the script to be evaluated later as an idle callback ๐ดโจ. the script will be run exactly once, the next time the event loop is entered and there are no events to process โ so it's the "whenever you're free, babe" option.
the command returns an identifier that can be used to cancel the delayed command using timer cancel or after cancel ๐ซ. and if an error occurs while executing the script, the background error will be reported by the command registered with interp bgerror ๐.
โญ timer sleep for delay ?unit?
delay must be a wide integer giving a time in the given unit (default: milliseconds). a negative number is treated as 0 ๐
โโ๏ธ.
the command sleeps for the given monotonic delay and then returns. while the command is sleeping, the application does not respond to events โ yes bestie, it's a full nap, nothing gets through ๐ด.
๐ธ timer sleep until timepoint ?unit?
timepoint must be a wide integer giving a wall clock time point in the given unit (default: seconds). a negative number is treated as 0 ๐
โโ๏ธ.
the command sleeps (at least) until the given wall clock time point and then returns. while it's sleeping, the application does not respond to events โ again, full nap, do not disturb ๐.
๐ after cancel id
cancels the execution of a delayed command that was previously scheduled โ. id indicates which command should be canceled; it must have been the return value from a previous timer or after command. if the command given by id has already been executed, then the timer cancel command has no effect โ it's a no-op, not a crisis, we move ๐
.
๐ timer info ?id?
this command returns information about existing event handlers ๐ต๏ธโโ๏ธ.
if no id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the timer and after command for this interpreter ๐.
if id is supplied, it specifies an existing handler; id must have been the return value from some previous call to timer or after, and it must not have triggered yet or been canceled โ ๏ธ.
in that case the command returns a list with two to three elements:
- the first element is the
scriptassociated withid๐ - the second element is either
idle,monotonicorwallclockto indicate what kind of event handler it is ๐ท๏ธ - a third list element is present for the kinds
monotonicorwallclock. this element is the scheduled execution time point in microseconds of the given clock type โฑ๏ธ
okay so about timer in, timer at and timer idle โ these forms assume the application is event driven ๐. the delayed commands will not be executed unless the application enters the event loop. in applications that are not normally event-driven, such as tclsh, the event loop can be entered with the vwait and update commands ๐ write that down.
๐ note that the output differs from after info. different list, different day, don't @ me.
โฑ๏ธ TIME UNITS โฑ๏ธ
some forms of the command take a time unit, bestie. available units are:
us(for microseconds)microsecondsms(for milliseconds)millisecondss(for seconds)seconds
โฆor any unique abbreviation ๐ cute and flexible.
๐ฅ TIME MAXIMUM VALUE ๐ฅ
the arguments delay and timepoint are bound to a resulting 63 bit clock value (in unit microseconds) ๐งฎ.
any higher value (which is after year 294441) will result in a time too far away error. yes, that's a real year. no, you will not be alive for it. still, the limit is the limit ๐.
๐ EXAMPLES ๐
this arranges for the command wake_up to be run in eight hours wall clock time (providing the event loop is active at that time, bestie โ don't forget the event loop):
timer at [clock add [clock seconds] 8 hours] seconds wake_up
ate. no crumbs. ๐ฝ๏ธ
๐ซถ SEE ALSO ๐ซถ
concat(n), interp(n), timer(n), update(n), vwait(n) โ go read them, they're all part of the friend group ๐
๐ซ KEYWORDS ๐ซ
cancel, delay, idle callback, sleep, time
that's the whole page, bestie ๐ โ signed off from Tcl 9.1, page timer(n), and yes the header said timer(n) / Tcl Built-In Commands at the top too. go forth and schedule responsibly ๐
โจ๐ฆ
๐ฆ where this page comes from
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 2025 The TCL Association
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms