Skip to content

Commit

Permalink
Add Timer::repeat() Timer::dealy()
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Sep 13, 2024
1 parent 0857164 commit c7dba86
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ public static function init(?EventInterface $event = null): void
}
}

/**
* Repeat.
*
* @param float $timeInterval
* @param callable $func
* @param array $args
* @return int
*/
public static function repeat(float $timeInterval, callable $func, array $args = []): int
{
return self::$event->repeat($timeInterval, $func, $args);
}

/**
* Delay.
*
* @param float $timeInterval
* @param callable $func
* @param array $args
* @return int
*/
public static function delay(float $timeInterval, callable $func, array $args = []): int
{
return self::$event->delay($timeInterval, $func, $args);
}

/**
* ALARM signal handler.
*
Expand All @@ -111,7 +137,7 @@ public static function signalHandle(): void
* @param bool $persistent
* @return int
*/
public static function add(float $timeInterval, callable $func, null|array $args = [], bool $persistent = true): int
public static function add(float $timeInterval, callable $func, ?array $args = [], bool $persistent = true): int
{
if ($timeInterval < 0) {
throw new RuntimeException('$timeInterval can not less than 0');
Expand Down Expand Up @@ -180,7 +206,7 @@ public static function sleep(float $delay): void
*
* @return void
*/
public static function tick(): void
protected static function tick(): void
{
if (empty(self::$tasks)) {
pcntl_alarm(0);
Expand Down

0 comments on commit c7dba86

Please sign in to comment.