for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Zored\Telegram\Util\Repeater;
class Repeater implements RepeaterInterface
{
private const NANO_IN_MILLISECOND = 1000;
/**
* @var int
*/
private $intervalMilliseconds;
private $maxTimeMilliseconds;
* @param int $intervalMilliseconds
public function __construct(int $intervalMilliseconds, int $maxTimeMilliseconds)
$this->intervalMilliseconds = $intervalMilliseconds;
$this->maxTimeMilliseconds = $maxTimeMilliseconds;
}
public function repeat(callable $callable): void
$time = 0;
while (true) {
if ($time >= $this->maxTimeMilliseconds) {
break;
$callable();
usleep($this->intervalMilliseconds * self::NANO_IN_MILLISECOND);
$time += $this->intervalMilliseconds;