Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/after.n @ 43

Last change on this file since 43 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 5.5 KB
Line 
1'\"
2'\" Copyright (c) 1990-1994 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: after.n,v 1.10 2007/12/13 15:22:32 dgp Exp $
9'\"
10.so man.macros
11.TH after n 7.5 Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15after \- Execute a command after a time delay
16.SH SYNOPSIS
17\fBafter \fIms\fR
18.sp
19\fBafter \fIms \fR?\fIscript script script ...\fR?
20.sp
21\fBafter cancel \fIid\fR
22.sp
23\fBafter cancel \fIscript script script ...\fR
24.sp
25\fBafter idle \fR?\fIscript script script ...\fR?
26.sp
27\fBafter info \fR?\fIid\fR?
28.BE
29
30.SH DESCRIPTION
31.PP
32This command is used to delay execution of the program or to execute
33a command in background sometime in the future.  It has several forms,
34depending on the first argument to the command:
35.TP
36\fBafter \fIms\fR
37\fIMs\fR must be an integer giving a time in milliseconds.
38The command sleeps for \fIms\fR milliseconds and then returns.
39While the command is sleeping the application does not respond to
40events.
41.TP
42\fBafter \fIms \fR?\fIscript script script ...\fR?
43In this form the command returns immediately, but it arranges
44for a Tcl command to be executed \fIms\fR milliseconds later as an
45event handler.
46The command will be executed exactly once, at the given time.
47The delayed command is formed by concatenating all the \fIscript\fR
48arguments in the same fashion as the \fBconcat\fR command.
49The command will be executed at global level (outside the context
50of any Tcl procedure).
51If an error occurs while executing the delayed command then
52the background error will be reported by the command
53registered with \fB interp bgerror\fR.
54The \fBafter\fR command returns an identifier that can be used
55to cancel the delayed command using \fBafter cancel\fR.
56.TP
57\fBafter cancel \fIid\fR
58Cancels the execution of a delayed command that
59was previously scheduled.
60\fIId\fR indicates which command should be canceled;  it must have
61been the return value from a previous \fBafter\fR command.
62If the command given by \fIid\fR has already been executed then
63the \fBafter cancel\fR command has no effect.
64.TP
65\fBafter cancel \fIscript script ...\fR
66This command also cancels the execution of a delayed command.
67The \fIscript\fR arguments are concatenated together with space
68separators (just as in the \fBconcat\fR command).
69If there is a pending command that matches the string, it is
70cancelled and will never be executed;  if no such command is
71currently pending then the \fBafter cancel\fR command has no effect.
72.TP
73\fBafter idle \fIscript \fR?\fIscript script ...\fR?
74Concatenates the \fIscript\fR arguments together with space
75separators (just as in the \fBconcat\fR command), and arranges
76for the resulting script to be evaluated later as an idle callback.
77The script will be run exactly once, the next time the event
78loop is entered and there are no events to process.
79The command returns an identifier that can be used
80to cancel the delayed command using \fBafter cancel\fR.
81If an error occurs while executing the script then the
82background error will be reported by the command
83registered with \fB interp bgerror\fR.
84.TP
85\fBafter info \fR?\fIid\fR?
86This command returns information about existing event handlers.
87If no \fIid\fR argument is supplied, the command returns
88a list of the identifiers for all existing
89event handlers created by the \fBafter\fR command for this
90interpreter.
91If \fIid\fR is supplied, it specifies an existing handler;
92\fIid\fR must have been the return value from some previous call
93to \fBafter\fR and it must not have triggered yet or been cancelled.
94In this case the command returns a list with two elements.
95The first element of the list is the script associated
96with \fIid\fR, and the second element is either
97\fBidle\fR or \fBtimer\fR to indicate what kind of event
98handler it is.
99.LP
100The \fBafter \fIms\fR and \fBafter idle\fR forms of the command
101assume that the application is event driven:  the delayed commands
102will not be executed unless the application enters the event loop.
103In applications that are not normally event-driven, such as
104\fBtclsh\fR, the event loop can be entered with the \fBvwait\fR
105and \fBupdate\fR commands.
106.SH "EXAMPLES"
107This defines a command to make Tcl do nothing at all for \fIN\fR
108seconds:
109.CS
110proc sleep {N} {
111   \fBafter\fR [expr {int($N * 1000)}]
112}
113.CE
114.PP
115This arranges for the command \fIwake_up\fR to be run in eight hours
116(providing the event loop is active at that time):
117.CS
118\fBafter\fR [expr {1000 * 60 * 60 * 8}] wake_up
119.CE
120.PP
121The following command can be used to do long-running calculations (as
122represented here by \fI::my_calc::one_step\fR, which is assumed to
123return a boolean indicating whether another step should be performed)
124in a step-by-step fashion, though the calculation itself needs to be
125arranged so it can work step-wise.  This technique is extra careful to
126ensure that the event loop is not starved by the rescheduling of
127processing steps (arranging for the next step to be done using an
128already-triggered timer event only when the event queue has been
129drained) and is useful when you want to ensure that a Tk GUI remains
130responsive during a slow task.
131.CS
132proc doOneStep {} {
133   if {[::my_calc::one_step]} {
134      \fBafter idle\fR [list \fBafter\fR 0 doOneStep]
135   }
136}
137doOneStep
138.CE
139
140.SH "SEE ALSO"
141concat(n), interp(n), update(n), vwait(n)
142
143.SH KEYWORDS
144cancel, delay, idle callback, sleep, time
Note: See TracBrowser for help on using the repository browser.