Tcl_DoWhenIdle(3)
π Tcl_DoWhenIdle β the "bestie do this when literally nothing else is happening" manual π
okay so bestie, this is Tcl_DoWhenIdle(3), straight out of the Tcl Library Procedures lineup. yes it's a C API page. yes it's giving very serious. no I will not be normal about it. let's go β¨
πΈ NAME πΈ
Tcl_DoWhenIdle, Tcl_CancelIdleCall β invoke a procedure when there are no pending events π¦
like. when everyone's done yapping and the event queue is finally quiet? that's when your girl shows up. periodt.
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_DoWhenIdle(proc, clientData)
Tcl_CancelIdleCall(proc, clientData)
π ARGUMENTS π
Tcl_IdleProc *proc(in) β Procedure to invoke. the main character function, the one that actually does the thing πvoid *clientData(in) β Arbitrary one-word value to pass toproc. it's giving "here's your little bag of stuff, don't lose it" π
π DESCRIPTION π
Tcl_DoWhenIdle arranges for proc to be invoked when the application becomes idle. and what counts as "idle"?? okay so: the application is considered to be idle when Tcl_DoOneEvent has been called, could not find any events to handle, and is about to go to sleep waiting for an event to occur. THAT moment. the little yawn before the nap. π΄ At this point all pending Tcl_DoWhenIdle handlers are invoked.
For each call to Tcl_DoWhenIdle there will be a single call to proc; after proc is invoked the handler is automatically removed. one call in, one call out, self-cleaning, we love an organized queen π§Ήβ¨
careful bestie:Tcl_DoWhenIdleis only usable in programs that useTcl_DoOneEventto dispatch events. noTcl_DoOneEvent, no idle callback. it's a package deal fr fr.
π the proc vibe check π
proc should have arguments and result that match the type Tcl_IdleProc:
typedef void Tcl_IdleProc(
void *clientData);
The clientData parameter to proc is a copy of the clientData argument given to Tcl_DoWhenIdle. Typically, clientData points to a data structure containing application-specific information about what proc should do. it's the lil note you pass to future-you π«Ά
π
Tcl_CancelIdleCall β the "nvm bestie" button π
Tcl_CancelIdleCall may be used to cancel one or more previous calls to Tcl_DoWhenIdle: if there is a Tcl_DoWhenIdle handler registered for proc and clientData, then it is removed without invoking it.
If there is more than one handler on the idle list that refers to proc and clientData, all of the handlers are removed. all of them. the whole group chat. gone. π
If no existing handlers match proc and clientData then nothing happens. no drama, no error, just vibes. π
π when to actually use this (the lore) π
Tcl_DoWhenIdle is most useful in situations where (a) a piece of work will have to be done but (b) it is possible that something will happen in the near future that will change what has to be done or require something different to be done. it's the "let me see how the situation develops before I commit" energy. main character patience. π
Tcl_DoWhenIdle allows the actual work to be deferred until all pending events have been processed. At this point the exact work to be done will presumably be known and it can be done exactly once. one and done. slay. β¨
For example, Tcl_DoWhenIdle might be used by an editor to defer display updates until all pending commands have been processed. Without this feature, redundant redisplays might occur in some situations, such as the processing of a command file. like bestie we do NOT need to redraw seventeen times in a row, that's not it π
π BUGS π
read this one. seriously. At present it is not safe for an idle callback to reschedule itself continuously. This will interact badly with certain features of Tk that attempt to wait for all idle callbacks to complete.
so if you would like for an idle callback to reschedule itself continuously, it is better to use a timer handler with a zero timeout period. do not fight Tk on this, Tk will win, Tk always wins π
π¦ SEE ALSO π¦
π KEYWORDS π
callback, defer, idle callback
and that's the whole page bestie, no notes, ate and left no crumbs πβ
this was Tcl version 7.5, dated 7.5-era energy, filed under Tcl_DoWhenIdle(3) in the Tcl Library Procedures. go forth and defer responsibly πππ«Ά
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- 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 on : a language model's rewrite of the original, under its terms