-
-
Notifications
You must be signed in to change notification settings - Fork 131
Closed
Labels
Description
I will start the counter with 0... every iteration value will be increased to 0.1 and the periodic timer will be stopped when
the counter value reaches 20.
My requirement is I have to pass the counter values to the front end with different time intervals.
For example, If the counter value is between 0 and 5... the time interval should be 0.1 seconds. When the counter value is between 5 and 10 the time interval should be 0.005... if it is between 10 and 15 then the time interval should be 0.00005. Like this, it goes on...
I tried the below code.
function testLoops($loop) {
$counter = 0;
$loop->addPeriodicTimer(0.1, function(TimerInterface $timer) use(&$counter, $loop) {
$counter = $counter+0.1;
if($counter > 5 && $counter <= 10) {
$this->Timer(0.005);
} else if($counter > 10 && $counter <= 15) {
$this->Timer(0.00005);
} else if($counter > 15 && $counter <= 20) {
$this->Timer(0.0000005);
}
echo "counter: ({$counter}) \n";
if($counter >= 20) {
$loop->cancelTimer($timer);
}
});
}
Could someone help me how to achieve this functionality.