# copyright (C) 1997-2006 Jean-Luc Fontaine (mailto:jfontain@free.fr)
# this program is free software: please read the COPYRIGHT file enclosed in this package or use the Help Copyright menu

# $Id: repeater.tcl,v 1.5 2006/01/28 19:16:59 jfontain Exp $


class repeater {

    proc repeater {this milliSeconds command} {
        set ($this,period) $milliSeconds
        set ($this,command) $command
    }

    proc ~repeater {this} {
        stop $this
    }

    proc start {this} {
        stop $this
        uplevel #0 $($this,command)
        set ($this,event) [after $($this,period) "repeater::start $this"]
    }

    proc stop {this} {
        catch {after cancel $($this,event)}
    }

}
