gk::schedule

Manage the execution of repetitive commands

Synopsis

gk::schedule tag command ?timer?
gk::schedule cancel tag

Description

The gk::schedule allows you to deal with executing repetitive commands so that commands do not cause a backlog. Tcl commands are added to a queue without duplicates, so that only a single Tcl command will be executed within a given time interval.

For example, lets say that in response to a received "move object" command, you would like to do an "update idletasks" after moving the object, so that the screen is updated. If you received thirty move object commands a second, you wouldn't be able to update the screen fast enough to process the messages, and they would be queued up. With gk::schedule, you could choose to process the messages right away, but only update the screen a maximum of ten times a second.

To schedule a command, you need to assign it a tag (all commands you wish to treat as part of the same batch, such as screen updates, should be given the same tag). You then specify the Tcl command to execute, and optionally a timer value (the default is 100 milliseconds), controlling how often commands will be executed. To cancel a scheduled command, if it has not already been executed, use the "cancel" option.

Example

proc moveObject {id coords} {
    # move the object...
    ...
    # update the screen a maximum of five times a second
    gk::schedule screenupdate "update idletasks" 200
}

GroupKit Reference Manual. Last updated March 13, 1998 by Mark Roseman.