Tcl_CreateTimerHandler(3)

πŸ“¦ version 9.1.0, in nixpkgs unstable

🌸 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 invoking proc. yes, micro. tiny. 🧚
  • int milliseconds (in) β€” how many milliseconds to wait before invoking proc.
  • Tcl_TimerProc *proc (in) β€” the procedure to invoke after milliseconds have elapsed.
  • void *clientData (in) β€” arbitrary one-word value to pass to proc. 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 to Tcl_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 to proc may not be made at the exact time given by the parameter: it will be made at the next opportunity after that time. so if Tcl_DoOneEvent is not called until long after the time has elapsed, or if there are other pending events to process before the call to proc, then the call to proc will 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&nbsp;&nbsp;&nbsp;7.5&nbsp;&nbsp;&nbsp;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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms