add timer tick

This commit is contained in:
Jerry
2023-02-10 13:12:20 +08:00
parent f03c0940da
commit df25aebd60
11 changed files with 132 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace ZM\Plugin\Traits;
use ZM\Annotation\Framework\Tick;
trait TickTrait
{
protected array $ticks = [];
public function addTimerTick(int $ms, callable $callback, int $worker_id = 0): void
{
$tick = new Tick($ms, $worker_id);
if (is_array($callback)) {
$tick->class = $callback[0];
$tick->method = $callback[1];
} elseif ($callback instanceof \Closure) {
$tick->method = $callback;
}
$this->ticks[] = $tick;
}
public function getTimerTicks(): array
{
return $this->ticks;
}
}