Timer with Uv Event on repeat mode did't work
webrobot1 opened this issue · comments
Try this code - doednt matter what time you will add to firs argument of Timer::add - it always wait only one microsecond
require_once '../vendor/autoload.php';
class A
{
function __construct()
{
$event = new \Workerman\Events\Uv;
\Workerman\Timer::init($event);
\Workerman\Timer::delAll();
$this->tick();
$event->loop();
}
public function tick()
{
echo (new \DateTime())->format("Y-m-d H:i:s:u").PHP_EOL;
\Workerman\Timer::add(10000, [$this, 'tick'], [], false);
}
}
new A();
as i see uv already remove from repo but this problem can be resolve in Event\Uv.php :
Before
case self::EV_TIMER_ONCE:
$repeat = $flag === self::EV_TIMER_ONCE ? 0 : (int)($fd * 1000);
$param = array($func, (array)$args, $flag, $fd, self::$_timerId);
$timerWatcher = \uv_timer_init();
\uv_timer_start($timerWatcher, 1, $repeat, function($watcher)use($param){
call_user_func_array([$this, 'timerCallback'], [$param]);
});
After
case self::EV_TIMER_ONCE:
$repeat = $flag === self::EV_TIMER_ONCE ? 0 : (int)($fd * 1000);
$param = array($func, (array)$args, $flag, $fd, self::$_timerId);
$timerWatcher = \uv_timer_init();
\uv_timer_start($timerWatcher, ($flag === self::EV_TIMER_ONCE ? (int)($fd * 1000):1), $repeat, function($watcher)use($param){
call_user_func_array([$this, 'timerCallback'], [$param]);
});
look how i change second argument at uv_timer_start function
I think Uv library is good idea because only this event library can work with Parallel thread library
Hi webrobot1
I am not familiar with UV. If you have fixed this issue, please send a pullrequest
all ok ?
There are too many changes in your last pull request on branch 4.1.
Please just send your uv-eventloop and do not change other files.
all work