2022-12-24 14:36:39 +01:00
|
|
|
<?php declare(strict_types=1);
|
2020-07-23 13:26:16 +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;
|
|
|
|
|
|
|
|
use function Amp\delay;
|
|
|
|
|
|
|
|
trait LoggingPause
|
|
|
|
{
|
|
|
|
use Logging;
|
|
|
|
/**
|
|
|
|
* Number of times loop was paused.
|
|
|
|
*/
|
2023-01-23 00:24:18 +01:00
|
|
|
private int $pauseCount = 0;
|
2020-07-23 13:26:16 +02:00
|
|
|
/**
|
|
|
|
* Last pause delay.
|
|
|
|
*/
|
2023-01-23 00:24:18 +01:00
|
|
|
private float $lastPause = 0;
|
2020-07-23 13:26:16 +02:00
|
|
|
/**
|
|
|
|
* Get number of times loop was paused.
|
|
|
|
*/
|
|
|
|
public function getPauseCount(): int
|
|
|
|
{
|
|
|
|
return $this->pauseCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get last pause.
|
|
|
|
*/
|
2023-01-23 00:24:18 +01:00
|
|
|
public function getLastPause(): float
|
2020-07-23 13:26:16 +02:00
|
|
|
{
|
|
|
|
return $this->lastPause;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Report pause, can be overriden for logging.
|
|
|
|
*
|
|
|
|
* @param integer $timeout Pause duration, 0 = forever
|
|
|
|
*
|
|
|
|
*/
|
2023-01-23 00:24:18 +01:00
|
|
|
protected function reportPause(float $timeout): void
|
2020-07-23 13:26:16 +02:00
|
|
|
{
|
2020-07-24 19:24:04 +02:00
|
|
|
parent::reportPause($timeout);
|
2020-07-23 13:26:16 +02:00
|
|
|
$this->pauseCount++;
|
2022-12-24 18:16:45 +01:00
|
|
|
$this->lastPause = $timeout;
|
2020-07-23 13:26:16 +02:00
|
|
|
}
|
|
|
|
}
|