1
0
mirror of https://github.com/danog/loop.git synced 2024-12-03 17:57:51 +01:00
loop/test/Traits/Resumable.php

46 lines
832 B
PHP
Raw Normal View History

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.
*
* @var int|float|null
*/
2020-07-21 21:45:22 +02:00
protected $interval = 0.1;
2020-07-21 19:12:11 +02:00
/**
* Set sleep interval.
*
* @param ?int $interval Interval
*
* @return void
*/
public function setInterval($interval): void
{
$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;
}
}