diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2004-04-21 12:03:26 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2004-04-21 12:03:26 (GMT) |
commit | 34af8dc64d2c552ced0e64653a3bc15adba7d3c2 (patch) | |
tree | 27174117365314148cc86b7c6718a909d0464437 /doc/after.n | |
parent | 8f9375dddadcfaf43de6c76aa4fcdb7f6a24cd99 (diff) | |
download | tcl-34af8dc64d2c552ced0e64653a3bc15adba7d3c2.zip tcl-34af8dc64d2c552ced0e64653a3bc15adba7d3c2.tar.gz tcl-34af8dc64d2c552ced0e64653a3bc15adba7d3c2.tar.bz2 |
Added examples from David Welton. [Patch 938820]
Diffstat (limited to 'doc/after.n')
-rw-r--r-- | doc/after.n | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/doc/after.n b/doc/after.n index 7e9a767..2dd9f2d 100644 --- a/doc/after.n +++ b/doc/after.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: after.n,v 1.3 2000/09/07 14:27:45 poenitz Exp $ +'\" RCS: @(#) $Id: after.n,v 1.4 2004/04/21 12:05:35 dkf Exp $ '\" .so man.macros .TH after n 7.5 Tcl "Tcl Built-In Commands" @@ -102,6 +102,43 @@ In applications that are not normally event-driven, such as \fBtclsh\fR, the event loop can be entered with the \fBvwait\fR and \fBupdate\fR commands. +.SH "EXAMPLES" +This defines a command to make Tcl do nothing at all for \fIN\fR +seconds: + +.CS +proc sleep {N} { + after [expr {int($N * 1000)}] +} +.CE + +This arranges for the command \fIwake_up\fR to be run in eight hours +(providing the event loop is active at that time): + +.CS +after [expr {1000 * 60 * 60 * 8}] wake_up +.CE + +The following command can be used to do long-running calculations (as +represented here by \fI::my_calc::one_step\fR, which is assumed to +return a boolean indicating whether another step should be performed) +in a step-by-step fashion, though the calculation itself needs to be +arranged so it can work step-wise. This technique is extra careful to +ensure that the event loop is not starved by the rescheduling of +processing steps (arranging for the next step to be done using an +already-triggered timer event only when the event queue has been +drained) and is useful when you want to ensure that a Tk GUI remains +responsive during a slow task. + +.CS +proc doOneStep {} { + if {[::my_calc::one_step]} { + after idle [list after 0 doOneStep] + } +} +doOneStep +.CE + .SH "SEE ALSO" bgerror(n), concat(n), update(n), vwait(n) |