2022-12-24 14:36:39 +01:00
|
|
|
<?php declare(strict_types=1);
|
2020-07-21 18:06:19 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2020-07-21 21:45:22 +02:00
|
|
|
trait Resumable
|
2020-07-21 18:06:19 +02:00
|
|
|
{
|
|
|
|
use Basic;
|
2020-07-21 19:12:11 +02:00
|
|
|
/**
|
|
|
|
* Set interval.
|
|
|
|
*
|
2020-07-22 18:18:57 +02:00
|
|
|
* @var ?int
|
2020-07-21 19:12:11 +02:00
|
|
|
*/
|
2020-07-22 18:18:57 +02:00
|
|
|
protected $interval = 100;
|
2020-07-21 19:12:11 +02:00
|
|
|
/**
|
|
|
|
* Set sleep interval.
|
|
|
|
*
|
|
|
|
* @param ?int $interval Interval
|
|
|
|
*
|
|
|
|
*/
|
2020-07-22 18:18:57 +02:00
|
|
|
public function setInterval(?int $interval): void
|
2020-07-21 19:12:11 +02:00
|
|
|
{
|
|
|
|
$this->interval = $interval;
|
|
|
|
}
|
2020-07-21 18:06:19 +02:00
|
|
|
/**
|
|
|
|
* Loop implementation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function loop(): Generator
|
|
|
|
{
|
2020-07-21 19:12:11 +02:00
|
|
|
$this->inited = true;
|
2022-12-23 20:45:00 +01:00
|
|
|
$this->pause($this->interval);
|
2020-07-21 18:06:19 +02:00
|
|
|
$this->ran = true;
|
|
|
|
}
|
|
|
|
}
|