1
0
mirror of https://github.com/danog/loop.git synced 2024-12-02 17:27:48 +01:00
loop/test/Traits/Resumable.php
2020-07-21 21:45:22 +02:00

46 lines
832 B
PHP

<?php
/**
* Resumable test trait.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2020 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/MIT MIT
*/
namespace danog\Loop\Test\Traits;
use Generator;
trait Resumable
{
use Basic;
/**
* Set interval.
*
* @var int|float|null
*/
protected $interval = 0.1;
/**
* Set sleep interval.
*
* @param ?int $interval Interval
*
* @return void
*/
public function setInterval($interval): void
{
$this->interval = $interval;
}
/**
* Loop implementation.
*
* @return Generator
*/
public function loop(): Generator
{
$this->inited = true;
yield $this->pause($this->interval);
$this->ran = true;
}
}