2022-12-24 14:36:39 +01:00
|
|
|
<?php declare(strict_types=1);
|
2020-07-21 18:06:19 +02:00
|
|
|
/**
|
|
|
|
* Loop 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;
|
|
|
|
|
2023-01-23 00:38:49 +01:00
|
|
|
use danog\Loop\Loop;
|
2020-07-21 18:06:19 +02:00
|
|
|
use danog\Loop\Test\LoopTest;
|
|
|
|
|
|
|
|
use function Amp\delay;
|
|
|
|
|
|
|
|
trait Basic
|
|
|
|
{
|
2020-07-23 13:26:16 +02:00
|
|
|
use Logging;
|
2020-07-21 18:06:19 +02:00
|
|
|
/**
|
|
|
|
* Check whether the loop inited.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $inited = false;
|
|
|
|
/**
|
|
|
|
* Check whether the loop ran.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $ran = false;
|
|
|
|
/**
|
|
|
|
* Check whether the loop inited.
|
|
|
|
*/
|
|
|
|
public function inited(): bool
|
|
|
|
{
|
|
|
|
return $this->inited;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Check whether the loop ran.
|
|
|
|
*/
|
|
|
|
public function ran(): bool
|
|
|
|
{
|
|
|
|
return $this->ran;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Loop implementation.
|
|
|
|
*/
|
2023-01-23 00:24:18 +01:00
|
|
|
public function loop(): ?float
|
2020-07-21 18:06:19 +02:00
|
|
|
{
|
|
|
|
$this->inited = true;
|
2022-12-24 17:24:51 +01:00
|
|
|
delay(0.1);
|
2020-07-21 18:06:19 +02:00
|
|
|
$this->ran = true;
|
2023-01-23 00:38:49 +01:00
|
|
|
return Loop::STOP;
|
2020-07-21 18:06:19 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get loop name.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __toString(): string
|
|
|
|
{
|
|
|
|
return LoopTest::LOOP_NAME;
|
|
|
|
}
|
|
|
|
}
|