TCL_CREATETIMERHANDLER(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– Tcl_CreateTimerHandler β€” bestie, it's a timer, it's a callback, it's a whole vibe πŸ’–

okay so this is a page from the Tcl Library Procedures manual, and it's about the two functions that let you say "hey Tcl, run this lil function for me later, mmkay?" β€” Tcl_CreateTimerHandler and Tcl_DeleteTimerHandler. Their whole job is literally just call a procedure at a given time. That's it. That's the girl. πŸŽ€


✨ NAME ✨

Tcl_CreateTimerHandler, Tcl_DeleteTimerHandler β€” call a procedure at a given time πŸ•


🌸 SYNOPSIS 🌸

#include <tcl.h>

Tcl_TimerToken
Tcl_CreateTimerHandler(milliseconds, proc, clientData)

Tcl_DeleteTimerHandler(token)

πŸ¦‹ ARGUMENTS πŸ¦‹

  • int milliseconds (in) β€” how many milliseconds we're waiting before we invoke proc. the countdown, the anticipation, the drama πŸ’…
  • Tcl_TimerProc *proc (in) β€” the procedure we're gonna invoke once milliseconds have elapsed. your main character function, basically πŸ‘‘
  • void *clientData (in) β€” an arbitrary one-word value that gets passed to proc. literally whatever you want, no judgement, it's giving "bring your own baggage" πŸŽ€
  • Tcl_TimerToken token (in) β€” the token for a timer handler you made earlier (i.e. the return value from some previous call to Tcl_CreateTimerHandler). your lil receipt, keep it safe 🧾

πŸ’œ DESCRIPTION πŸ’œ

Tcl_CreateTimerHandler arranges for proc to be invoked at a time milliseconds milliseconds in the future. slay. ✨

But here's the tea, bestie: the callback to proc is 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. if your program isn't doing the event-dispatch thing, this function is just gonna sit there looking cute and doing nothing. πŸ’€

And 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. so like… it's a vibe, not a stopwatch. ⏰

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. so you're passing your own lil info bundle through the void and getting it handed right back. iconic. 🫢

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. no error, no drama, just nothing. πŸ“

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. protected. unbothered. πŸ’…

🌈 SEE ALSO 🌈


⭐ KEYWORDS ⭐

callback, clock, handler, timer


and that's the whole page, bestie!! you ate πŸ’– this was Tcl 7.5 of the Tcl Library Procedures, filed under Tcl_CreateTimerHandler(3tcl) β€” go forth and schedule your callbacks responsibly, ily, mwah πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from