-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathafter.phpt
46 lines (41 loc) · 1.03 KB
/
after.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--TEST--
swoole_timer: swoole_timer_after,swoole_timer_exists,swoole_timer_clear
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
class TimerTest {
public static $count = 0;
private $timer_id = null;
protected function resetTimer($ms) {
if ($this->timer_id && Swoole\Timer::exists($this->timer_id)) {
Swoole\Timer::clear($this->timer_id);
$this->timer_id = null;
}
if (self::$count == 10) {
return;
}
$this->timer_id = Swoole\Timer::after($ms, array($this, 'onTimerTick'));
Assert::assert($this->timer_id > 0);
}
public function onTimerTick() {
self::$count++;
echo "onTimerTick:" . self::$count . "\n";
$this->resetTimer(10);
}
}
$timer_test = new TimerTest();
$timer_test->onTimerTick();
?>
--EXPECT--
onTimerTick:1
onTimerTick:2
onTimerTick:3
onTimerTick:4
onTimerTick:5
onTimerTick:6
onTimerTick:7
onTimerTick:8
onTimerTick:9
onTimerTick:10