This repository has been archived on 2018-04-01. You can view files and clone it, but cannot push or open issues or pull requests.
php-asio/tests/02-timer.phpt

23 lines
603 B
PHP

--TEST--
Test for `Timer`.
--FILE--
<?php
$service = new Asio\Service;
$timer = $service->addTimer();
if ($ec = $timer->expiresFromNow(200))
die('Timer::expire() failed. '.posix_strerror($ec));
$start_time = microtime(true);
$timer->wait(function ($timer, $ec) use ($start_time) {
if ($ec) {
echo 'Error on Timer::wait(). ', posix_strerror($ec);
return;
}
$end_time = microtime(true);
$duration = intval(1000 * ($end_time - $start_time));
if ($duration != 200)
echo "Bad duration. Expected 200ms, got ${duration}ms";
});
$service->run($ec);
?>
--EXPECT--