2020-07-21 18:06:19 +02:00
|
|
|
<?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;
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
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.
|
|
|
|
*
|
|
|
|
* @return Generator
|
|
|
|
*/
|
|
|
|
public function loop(): Generator
|
|
|
|
{
|
2020-07-21 19:12:11 +02:00
|
|
|
$this->inited = true;
|
|
|
|
yield $this->pause($this->interval);
|
2020-07-21 18:06:19 +02:00
|
|
|
$this->ran = true;
|
|
|
|
}
|
|
|
|
}
|