1after(n)                     Tcl Built-In Commands                    after(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       after - Execute a command after a time delay
9

SYNOPSIS

11       after ms
12
13       after ms ?script script script ...?
14
15       after cancel id
16
17       after cancel script script script ...
18
19       after idle ?script script script ...?
20
21       after info ?id?
22_________________________________________________________________
23
24

DESCRIPTION

26       This  command is used to delay execution of the program or to execute a
27       command in background sometime in the future.  It  has  several  forms,
28       depending on the first argument to the command:
29
30       after ms
31              Ms  must  be an integer giving a time in milliseconds.  The com‐
32              mand sleeps for ms milliseconds and  then  returns.   While  the
33              command is sleeping the application does not respond to events.
34
35       after ms ?script script script ...?
36              In  this  form  the command returns immediately, but it arranges
37              for a Tcl command to be executed ms  milliseconds  later  as  an
38              event  handler.   The  command will be executed exactly once, at
39              the given time.  The delayed command is formed by  concatenating
40              all  the script arguments in the same fashion as the concat com‐
41              mand.  The command will be executed at global level (outside the
42              context of any Tcl procedure).  If an error occurs while execut‐
43              ing the delayed command then the bgerror mechanism  is  used  to
44              report  the error.  The after command returns an identifier that
45              can be used to cancel the delayed command using after cancel.
46
47       after cancel id
48              Cancels the execution of a delayed command that  was  previously
49              scheduled.   Id  indicates which command should be canceled;  it
50              must have been the return value from a previous  after  command.
51              If  the  command  given by id has already been executed then the
52              after cancel command has no effect.
53
54       after cancel script script ...
55              This command also cancels the execution of  a  delayed  command.
56              The  script arguments are concatenated together with space sepa‐
57              rators (just as in the concat command).  If there is  a  pending
58              command  that matches the string, it is cancelled and will never
59              be executed;  if no such command is currently pending  then  the
60              after cancel command has no effect.
61
62       after idle script ?script script ...?
63              Concatenates the script arguments together with space separators
64              (just as in the concat command), and arranges for the  resulting
65              script  to  be  evaluated later as an idle callback.  The script
66              will be run exactly once,  the  next  time  the  event  loop  is
67              entered and there are no events to process.  The command returns
68              an identifier that can be used to  cancel  the  delayed  command
69              using  after  cancel.   If  an  error occurs while executing the
70              script then the bgerror mechanism is used to report the error.
71
72       after info ?id?
73              This command returns information about existing event  handlers.
74              If no id argument is supplied, the command returns a list of the
75              identifiers for all existing event handlers created by the after
76              command  for  this interpreter.  If id is supplied, it specifies
77              an existing handler; id must have been  the  return  value  from
78              some  previous  call to after and it must not have triggered yet
79              or been cancelled.  In this case the command returns a list with
80              two elements.  The first element of the list is the script asso‐
81              ciated with id, and the second element is either idle  or  timer
82              to indicate what kind of event handler it is.
83
84       The after ms and after idle forms of the command assume that the appli‐
85       cation is event driven:  the delayed  commands  will  not  be  executed
86       unless the application enters the event loop.  In applications that are
87       not normally event-driven, such as tclsh, the event loop can be entered
88       with the vwait and update commands.
89

EXAMPLES

91       This defines a command to make Tcl do nothing at all for N seconds:
92              proc sleep {N} {
93                 after [expr {int($N * 1000)}]
94              }
95
96       This arranges for the command wake_up to be run in eight hours (provid‐
97       ing the event loop is active at that time):
98              after [expr {1000 * 60 * 60 * 8}] wake_up
99
100       The following command can be used to do long-running  calculations  (as
101       represented  here  by ::my_calc::one_step, which is assumed to return a
102       boolean indicating whether another step should be performed) in a step-
103       by-step  fashion, though the calculation itself needs to be arranged so
104       it can work step-wise.  This technique is extra careful to ensure  that
105       the  event  loop is not starved by the rescheduling of processing steps
106       (arranging for the next step to  be  done  using  an  already-triggered
107       timer  event  only when the event queue has been drained) and is useful
108       when you want to ensure that a Tk GUI remains responsive during a  slow
109       task.
110              proc doOneStep {} {
111                 if {[::my_calc::one_step]} {
112                    after idle [list after 0 doOneStep]
113                 }
114              }
115              doOneStep
116
117

SEE ALSO

119       bgerror(n), concat(n), update(n), vwait(n)
120
121

KEYWORDS

123       cancel, delay, idle callback, sleep, time
124
125
126
127Tcl                                   7.5                             after(n)
Impressum