Name

after — Sleep / delayed script evaluation

Synopsis

after milliseconds [script] | info [event] | cancel event [event...] | idle [script]

Description

The after command is used, in the simple case, to simply halt evaluation of the script for milliseconds milliseconds, or execute a script after that number of milliseconds.

The after command can also be used to manage timer events in Hecl via the info and cancel subcommands, which, respectively, return information about existing events, and allow the cancellation of events.

Example

Pause for 1 second:

after 1000

Run script after 10 seconds, but do not pause execution of the main script:

after 10000 { puts "hello, later world"	}

Cancel all timers:

for {set i 1} {< $i 11} {incr $i} {
    puts [after [* 10000 [random]] [list puts "Event number $i"]]
}

after 5000

foreach e [after info] {
    after cancel $e
    puts "Event $e cancelled"
}

twait forever

Will produce, on average, something like the following:

timer#1
timer#2
timer#3
timer#4
timer#5
timer#6
timer#7
timer#8
timer#9
timer#10
Event number 9
Event number 4
Event number 10
Event timer#5 cancelled
Event timer#1 cancelled
Event timer#7 cancelled
Event timer#3 cancelled
Event timer#2 cancelled
Event timer#6 cancelled
Event timer#8 cancelled