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

DESCRIPTION

25       This  command is used to delay execution of the program or to execute a
26       command in background sometime in the future.  It  has  several  forms,
27       depending on the first argument to the command:
28
29       after ms
30              Ms  must  be an integer giving a time in milliseconds.  The com‐
31              mand sleeps for ms milliseconds and  then  returns.   While  the
32              command is sleeping the application does not respond to events.
33
34       after ms ?script script script ...?
35              In  this  form  the command returns immediately, but it arranges
36              for a Tcl command to be executed ms  milliseconds  later  as  an
37              event  handler.   The  command will be executed exactly once, at
38              the given time.  The delayed command is formed by  concatenating
39              all  the script arguments in the same fashion as the concat com‐
40              mand.  The command will be executed at global level (outside the
41              context of any Tcl procedure).  If an error occurs while execut‐
42              ing the delayed  command  then  the  background  error  will  be
43              reported  by  the  command  registered with interp bgerror.  The
44              after command returns an identifier that can be used  to  cancel
45              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 canceled 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 background error will be reported by the command
71              registered with interp bgerror.
72
73       after info ?id?
74              This command returns information about existing event  handlers.
75              If no id argument is supplied, the command returns a list of the
76              identifiers for all existing event handlers created by the after
77              command  for  this interpreter.  If id is supplied, it specifies
78              an existing handler; id must have been  the  return  value  from
79              some  previous  call to after and it must not have triggered yet
80              or been canceled.  In this case the command returns a list  with
81              two elements.  The first element of the list is the script asso‐
82              ciated with id, and the second element is either idle  or  timer
83              to indicate what kind of event handler it is.
84
85       The after ms and after idle forms of the command assume that the appli‐
86       cation is event driven:  the delayed  commands  will  not  be  executed
87       unless the application enters the event loop.  In applications that are
88       not normally event-driven, such as tclsh, the event loop can be entered
89       with the vwait and update commands.
90

EXAMPLES

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

SEE ALSO

122       concat(n), interp(n), update(n), vwait(n)
123

KEYWORDS

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