Tcl_CreateTimerHandler(3)
πΈ Tcl_CreateTimerHandler(3) β the Tcl Library Procedures edition, bestie πΈ
okay so quick vibe check: this is one of those Tcl Library Procedures pages, and it's literally about making things happen later. like, scheduling your future self to do a thing. main character energy for callbacks, fr fr.
β¨ NAME β¨
Tcl_CreateTimerHandler, TclCreateTimerHandlerMicroSeconds, Tcl_DeleteTimerHandler β call a procedure at a given time π
π SYNOPSIS π
#include <tcl.h>
Tcl_TimerToken
Tcl_CreateTimerHandler(milliseconds, proc, clientData)
Tcl_TimerToken
Tcl_CreateTimerHandlerMicroSeconds(microseconds, proc, clientData)
Tcl_DeleteTimerHandler(token)
π¦ ARGUMENTS π¦
long_long microseconds(in) β how many microseconds to wait before invokingproc. yes, micro. tiny. π§int milliseconds(in) β how many milliseconds to wait before invokingproc.Tcl_TimerProc *proc(in) β the procedure to invoke aftermillisecondshave elapsed.void *clientData(in) β arbitrary one-word value to pass toproc. literally whatever you want, it just gets handed back to you later π«ΆTcl_TimerToken token(in) β token for a previously created timer handler (the return value from some previous call toTcl_CreateTimerHandler).
π DESCRIPTION π
Tcl_CreateTimerHandler arranges for proc to be invoked at a time milliseconds milliseconds in the future. and Tcl_CreateTimerHandlerMicroSeconds arranges for proc to be invoked at a time microseconds microseconds in the future. same energy, different unit β
the callback to proc will be made by Tcl_DoOneEvent, so Tcl_CreateTimerHandler is only useful in programs that dispatch events through Tcl_DoOneEvent or through Tcl commands such as vwait. no event loop, no callback β that's the whole deal π
β οΈ also, the call toprocmay not be made at the exact time given by the parameter: it will be made at the next opportunity after that time. so ifTcl_DoOneEventis not called until long after the time has elapsed, or if there are other pending events to process before the call toproc, then the call toprocwill be delayed. it's giving "fashionably late", not "on time". π
Proc should have arguments and return value that match the type Tcl_TimerProc:
typedef void Tcl_TimerProc(
void *clientData);
the clientData parameter to proc is a copy of the clientData argument given to Tcl_CreateTimerHandler when the callback was created. typically, clientData points to a data structure containing application-specific information about what to do in proc. iykyk π
both functions return a token. in case of Tcl_CreateTimerHandlerMicroSeconds, the return value is NULL if the given time interval is to much in the future and may not be represented. this is a theoretical case, as it is in around 26 thousand years π₯ (yes, thousand. you're fine, bestie.) meanwhile Tcl_CreateTimerHandler does not check for overflow and never returns NULL.
Tcl_DeleteTimerHandler may be called to delete a previously created timer handler. it deletes the handler indicated by token so that no call to proc will be made; if that handler no longer exists (e.g. because the time period has already elapsed and proc has been invoked) then Tcl_DeleteTimerHandler does nothing. iconic no-op behaviour, honestly π
and the tokens returned by Tcl_CreateTimerHandler never have a value of NULL, so if NULL is passed to Tcl_DeleteTimerHandler then the procedure does nothing. safe. slay. β¨
π SEE ALSO π
after(n), Tcl_CreateFileHandler(3), Tcl_DoWhenIdle(3)
π KEYWORDS π
callback, clock, handler, timer
and that's the whole page, bestie β no cap. this one's from the Tcl Library Procedures crew, version 7.5, and it's dated 7.5 too (the footer says Tcl 7.5 Tcl_CreateTimerHandler(3)). go schedule something cute, and remember: your timer might be late but it's never wrong. periodt ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1990 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms