Execute a command after a time delay

## NAME

after - Execute a command after a time delay

## SYNOPSIS

$widget->after(ms)
$id = $widget->after(ms,callback)
$widget->afterCancel(id)
$id = $widget->repeat(ms,callback)
$id = $widget->afterIdle(callback)
$id->cancel

## DESCRIPTION

These methods are used to delay execution of the program or to execute a callback in background after a delay. Specifying $widget as above is necessary as core Tk associates the pending actions with a \fbMainWindow and perl/Tk can support multiple \fbMainWindows.

As of Tk-b10 after is implemented as a perl layer on the core Tk::after mechanism. The returned $id is now a perl object. This object is associated with $widget and is automatically cancelled when $widget is destroyed.

The methods take the following forms:

$widget->after(ms)
  Ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to X events or any other events.
$id = $widget->after(ms,callback)
  In this form the command returns immediately, but it arranges for callback be executed ms milliseconds later as a background event handler. If an error occurs while executing the delayed command then the Tk::Error mechanism is used to report the error. The after command returns an identifier that can be used to cancel the delayed command using afterCancel.
$id = $widget->repeat(ms,callback)
  This form is new as of Tk-b10 and is implemented in the perl wrapper on the core Tk::after command. The callback is executed ms milliseconds later, and then repeats every ms milliseconds until cancelled. If an error occurs while executing the delayed command then the Tk::Error mechanism is used to report the error. The repeat command returns an identifier that can be used to cancel the delayed command using afterCancel.
$widget->afterCancel(id)
  Cancels the execution of a delayed command that was previously scheduled. Id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by id has already been executed then the afterCancel command has no effect.
$id->cancel
  A method of the underlying class used to implement the wrapper. While the class design is subject to change this method is likely to remain. Behaviour is as for afterCancel.
$id = $widget->afterIdle(\fcallback)
  Arranges for callback evaluated later as an idle handler (the script runs the next time the Tk event loop is entered and there are no events to process). The command returns an identifier that can be used to cancel the delayed command using afterCancel. If an error occurs while executing the script then the Tk::Error mechanism is used to report the error.

## SEE ALSO

Tk::Error callbacks

## KEYWORDS

cancel, delay, sleep, time