Tcl_CreateTimerHandler(3)

πŸ’– NAME πŸ’–

Tcl_CreateTimerHandler, Tcl_DeleteTimerHandler β€” bestie, these two literally call a procedure at a given time ⏰✨

This is all from the Tcl Library Procedures manual, page Tcl_CreateTimerHandler(3), and no cap we're going through every single bit of it.


✨ SYNOPSIS ✨

#include <tcl.h>

Tcl_TimerToken
Tcl_CreateTimerHandler(milliseconds, proc, clientData)

Tcl_DeleteTimerHandler(token)

Like, that's the whole vibe right there 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • int milliseconds (in) β€” how many milliseconds we're waiting before proc gets invoked. So it's giving "patience, queen" πŸ’…
  • Tcl_TimerProc *proc (in) β€” the procedure to invoke once milliseconds have elapsed. This is the main character of the whole operation fr fr.
  • void *clientData (in) β€” an arbitrary one-word value you pass along to proc. Literally anything, your call, no judgement 🌸
  • Tcl_TimerToken token (in) β€” the token for a previously created timer handler. It's the return value from some previous call to Tcl_CreateTimerHandler, iykyk πŸ”‘

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so Tcl_CreateTimerHandler arranges for proc to be invoked at a time milliseconds milliseconds in the future. That's it, that's the whole thing. The callback to proc will be made by Tcl_DoOneEvent, which means Tcl_CreateTimerHandler is only useful in programs that dispatch events through Tcl_DoOneEvent or through Tcl commands such as vwait. If your program isn't doing that, this function is just standing there being gorgeous with nothing to do 😭

And bestie, listen: the call to proc may not be made at the exact time given by milliseconds. It will be made at the next opportunity after that time. For example, 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. She's not late, she's just busy processing other events πŸ’€

proc should have arguments and a 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. So like, it's your little backpack of context that gets handed over πŸŽ’βœ¨


πŸ’œ deleting a timer, the sad part πŸ’œ

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 β€” the plan is cancelled, the vibe is called off, nothing happens πŸ™ˆ

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. It's fine. It's fine. Everything's fine 🧚

Also important: 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, harmless, iconic behavior honestly πŸ‘‘


🌈 SEE ALSO 🌈


⭐ KEYWORDS ⭐

callback, clock, handler, timer β€” that's the whole mood board πŸŽ€


And that's the page, bestie πŸ’– This was the Tcl Library Procedures manual, page Tcl_CreateTimerHandler(3), and it's from Tcl version 7.5 β€” go forth and schedule your callbacks, you absolute legend 🫢✨

πŸ“¦ where this page comes from