Navigation
Synopsis Define interactive, time-dependent, behaviour.
Function FProperty timer (TimerAction (TimerInfo) ti, void () cbb)
Description This property allows you to execute a callback cbb after a specified time, and also allows you to delay, cancel and restart the timer.

At the start and after each event (i.e. other callback) the callback ti will be called. This callback should have type TimerAction (TimerInfo). The callback is given a TimerInfo structure:
rascal>data TimerInfo  = stopped(int timeSinceLast) 
>>>>>>>		| running(int timeLeft);
ok
This indicates if the timer has stopped and the time since the last execution of the timer (in milliseconds, initially 0) or if the timer is running and the time that is still left till the callback cbb will be executed.

The callback ti must then return a TimerAction which indicates what action it want to undertake:
rascal>data TimerAction = restart(int delay)
>>>>>>>		 | stop()
>>>>>>>		 | noChange();
ok
  • restart(int delay) indicates that the timer is restarted and that the callback cbb will be executed delay milliseconds from now. This can also be used to delay the timer.
  • stop() indicates that the timer is cancelled.
  • noChange() indicates that timer no change to the timer.
Examples
c = false;
void executeTimer(){
	c = !c;
}
TimerAction timeAction(TimerInfo t){
        if(stopped(_) := t){
		return restart(300);
	} else {
		return noChange();
	}
}
Color getColor(){
	return c ? color("red") : color("green");
}
e = ellipse(fillColor(getColor), timer(timeAction,executeTimer),shrink(0.5));
render(e);
timer
Pitfalls Unfortunately we cannot show an animated version of the figure above, try it out in rascal yourself.
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.