1
0
mirror of https://github.com/danog/loop.git synced 2024-11-30 04:19:04 +01:00
This commit is contained in:
Daniil Gentili 2022-12-23 20:45:00 +01:00
parent 47d2d51442
commit afcf214f24
18 changed files with 106 additions and 114 deletions

View File

@ -39,7 +39,7 @@ namespace danog\Loop;
abstract class Loop
{
abstract public function loop(): \Generator;
abstract public function loop();
abstract public function __toString(): string;
public function start(): bool;

View File

@ -19,16 +19,16 @@ Loop::run(function () {
};
$loop = new GenericLoop($callable, "Loop number $x");
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
yield delay(5000);
delay(5000);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
echo "OK done, waiting 5 more seconds!".PHP_EOL;
yield delay(5000);
delay(5000);
echo "Closing all loops!".PHP_EOL;
yield delay(10);
delay(10);
});

View File

@ -7,7 +7,6 @@ use danog\Loop\Generic\PeriodicLoop;
use function Amp\delay;
Loop::run(function () {
/** @var PeriodicLoop[] */
$loops = [];
for ($x = 0; $x < 10; $x++) {
@ -19,16 +18,15 @@ Loop::run(function () {
};
$loop = new PeriodicLoop($callable, "Loop number $x", 1000);
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
yield delay(5000);
delay(5000);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
echo "OK done, waiting 5 more seconds!".PHP_EOL;
yield delay(5000);
delay(5000);
echo "Closing all loops!".PHP_EOL;
yield delay(10);
});
delay(10);

View File

@ -37,13 +37,13 @@ class MyLoop extends Loop
*
* @return \Generator
*/
public function loop(): \Generator
public function loop()
{
$callable = $this->callable;
$number = 0;
while (true) {
$number = yield from $callable($number);
$number = $callable($number);
echo "$this: $number".PHP_EOL;
}
}
@ -82,16 +82,15 @@ class MyLoop extends Loop
}
}
AmpLoop::run(function () {
$function = function (int $number): \Generator {
yield delay(1000);
$function = function (int $number) {
delay(1000);
return $number + 1;
};
$loops = [];
for ($x = 0; $x < 10; $x++) {
$loop = new MyLoop($function, "Loop number $x");
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
});

View File

@ -29,11 +29,11 @@ class MyLoop extends ResumableLoop
*
* @return \Generator
*/
public function loop(): \Generator
public function loop()
{
$number = 0;
while (true) {
yield $this->pause(1000);
$this->pause(1000);
echo "$this: $number".PHP_EOL;
$number++;
}
@ -73,17 +73,15 @@ class MyLoop extends ResumableLoop
}
}
AmpLoop::run(function () {
$loops = [];
for ($x = 0; $x < 10; $x++) {
$loop = new MyLoop("Loop number $x");
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
yield delay(5000);
delay(5000);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
});

View File

@ -29,11 +29,11 @@ class ResSigLoop extends ResumableSignalLoop
*
* @return \Generator
*/
public function loop(): \Generator
public function loop()
{
$number = 0;
while (true) {
if (yield $this->waitSignal($this->pause(1000))) {
if ($this->waitSignal($this->pause(1000))) {
echo "Got exit signal in $this!".PHP_EOL;
return;
}
@ -52,24 +52,22 @@ class ResSigLoop extends ResumableSignalLoop
}
}
Loop::run(function () {
/** @var ResSigLoop[] */
$loops = [];
for ($x = 0; $x < 10; $x++) {
$loop = new ResSigLoop("Loop number $x");
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
yield delay(5000);
delay(5000);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
echo "OK done, waiting 5 more seconds!".PHP_EOL;
yield delay(5000);
delay(5000);
echo "Closing all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->signal(true);
}
});

View File

@ -29,11 +29,11 @@ class SigLoop extends SignalLoop
*
* @return \Generator
*/
public function loop(): \Generator
public function loop()
{
$number = 0;
while (true) {
if (yield $this->waitSignal(delay(1000))) {
if ($this->waitSignal(delay(1000))) {
echo "Got exit signal in $this!".PHP_EOL;
return;
}
@ -52,18 +52,17 @@ class SigLoop extends SignalLoop
}
}
Loop::run(function () {
/** @var SigLoop[] */
$loops = [];
for ($x = 0; $x < 10; $x++) {
$loop = new SigLoop("Loop number $x");
$loop->start();
yield delay(100);
delay(100);
$loops []= $loop;
}
yield delay(5000);
delay(5000);
echo "Closing all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->signal(true);
}
});

View File

@ -30,7 +30,7 @@ interface LoopInterface
*
* @return \Generator
*/
public function loop(): \Generator;
public function loop();
/**
* Get name of the loop.
*

View File

@ -42,7 +42,7 @@ interface ResumableLoopInterface extends LoopInterface
/**
* Defer resuming the loop to next tick.
*
* Multiple consecutive calls will yield only one resume.
* Multiple consecutive calls will only one resume.
*
* @return Promise Resolved when the loop is paused again
*/

View File

@ -109,7 +109,7 @@ trait ResumableLoop
/**
* Defer resuming the loop to next tick.
*
* Multiple consecutive calls will yield only one resume.
* Multiple consecutive calls will only one resume.
*
* @return Future<null> Resolved when the loop is paused again
*/

View File

@ -31,7 +31,7 @@ class GenericTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testGeneric(bool $stopSig): \Generator
public function testGeneric(bool $stopSig)
{
$runCount = 0;
$pauseTime = GenericLoop::PAUSE;
@ -40,7 +40,7 @@ class GenericTest extends AsyncTestCase
$runCount++;
return $pauseTime;
};
yield from $this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
@ -50,7 +50,7 @@ class GenericTest extends AsyncTestCase
return $this->pauseTime;
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
@ -60,7 +60,7 @@ class GenericTest extends AsyncTestCase
return $this->pauseTime;
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
}
/**
* Test generator loop.
@ -71,39 +71,39 @@ class GenericTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testGenerator(bool $stopSig): \Generator
public function testGenerator(bool $stopSig)
{
$runCount = 0;
$pauseTime = GenericLoop::PAUSE;
$callable = function () use (&$runCount, &$pauseTime, &$zis): \Generator {
$callable = function () use (&$runCount, &$pauseTime, &$zis) {
$zis = $this;
yield delay(1);
delay(1);
$runCount++;
return $pauseTime;
};
yield from $this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
public function run(): \Generator
public function run()
{
yield delay(1);
delay(1);
$this->runCount++;
return $this->pauseTime;
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
public function run(): \Generator
public function run()
{
yield delay(1);
delay(1);
$this->runCount++;
return $this->pauseTime;
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
}
/**
* Test promise loop.
@ -114,7 +114,7 @@ class GenericTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testPromise(bool $stopSig): \Generator
public function testPromise(bool $stopSig)
{
$runCount = 0;
$pauseTime = GenericLoop::PAUSE;
@ -123,7 +123,7 @@ class GenericTest extends AsyncTestCase
$runCount++;
return new Success($pauseTime);
};
yield from $this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $pauseTime, $stopSig, $zis, true);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
@ -133,7 +133,7 @@ class GenericTest extends AsyncTestCase
return new Success($this->pauseTime);
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$obj = new class() {
public $pauseTime = GenericLoop::PAUSE;
public $runCount = 0;
@ -143,7 +143,7 @@ class GenericTest extends AsyncTestCase
return new Success($this->pauseTime);
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->pauseTime, $stopSig, $zisNew, false);
}
/**
* Fixture assertions for started loop.
@ -170,7 +170,7 @@ class GenericTest extends AsyncTestCase
*
* @return \Generator
*/
private function fixtureAssertions(callable $closure, int &$runCount, ?int &$pauseTime, bool $stopSig, &$zis, bool $checkZis): \Generator
private function fixtureAssertions(callable $closure, int &$runCount, ?int &$pauseTime, bool $stopSig, &$zis, bool $checkZis)
{
$loop = new class($closure, Fixtures::LOOP_NAME) extends GenericLoop implements LoggingPauseInterface {
use LoggingPause;
@ -185,7 +185,7 @@ class GenericTest extends AsyncTestCase
$this->assertEquals(0, $loop->getPauseCount());
$loop->start();
yield delay(2);
delay(2);
if ($checkZis) {
$this->assertEquals($loop, $zis);
} else {
@ -199,21 +199,21 @@ class GenericTest extends AsyncTestCase
$pauseTime = 100;
$loop->resume();
yield delay(2);
delay(2);
$this->fixtureStarted($loop);
$this->assertEquals(2, $runCount);
$this->assertEquals(2, $loop->getPauseCount());
$this->assertEquals(100, $loop->getLastPause());
yield delay(48);
delay(48);
$this->fixtureStarted($loop);
$this->assertEquals(2, $runCount);
$this->assertEquals(2, $loop->getPauseCount());
$this->assertEquals(100, $loop->getLastPause());
yield delay(60);
delay(60);
$this->fixtureStarted($loop);
$this->assertEquals(3, $runCount);
@ -221,7 +221,7 @@ class GenericTest extends AsyncTestCase
$this->assertEquals(100, $loop->getLastPause());
$loop->resume();
yield delay(1);
delay(1);
$this->assertEquals(4, $runCount);
$this->assertEquals(4, $loop->getPauseCount());
@ -233,7 +233,7 @@ class GenericTest extends AsyncTestCase
$pauseTime = GenericLoop::STOP;
$loop->resume();
}
yield delay(1);
delay(1);
$this->assertEquals($stopSig ? 4 : 5, $runCount);
$this->assertEquals(4, $loop->getPauseCount());
$this->assertEquals(100, $loop->getLastPause());

View File

@ -30,13 +30,13 @@ class LoopTest extends Fixtures
*
* @dataProvider provideBasic
*/
public function testLoop(BasicInterface $loop): \Generator
public function testLoop(BasicInterface $loop)
{
$this->assertPreStart($loop);
$this->assertTrue($loop->start());
$this->assertAfterStart($loop);
yield delay(110);
delay(110);
$this->assertFinal($loop);
}

View File

@ -31,7 +31,7 @@ class PeriodicTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testGeneric(bool $stopSig): \Generator
public function testGeneric(bool $stopSig)
{
$runCount = 0;
$retValue = false;
@ -40,7 +40,7 @@ class PeriodicTest extends AsyncTestCase
$runCount++;
return $retValue;
};
yield from $this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
@ -50,7 +50,7 @@ class PeriodicTest extends AsyncTestCase
return $this->retValue;
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
@ -60,7 +60,7 @@ class PeriodicTest extends AsyncTestCase
return $this->retValue;
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
}
/**
* Test generator loop.
@ -71,39 +71,39 @@ class PeriodicTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testGenerator(bool $stopSig): \Generator
public function testGenerator(bool $stopSig)
{
$runCount = 0;
$retValue = false;
$callable = function () use (&$runCount, &$retValue, &$zis): \Generator {
$callable = function () use (&$runCount, &$retValue, &$zis) {
$zis = $this;
yield delay(1);
delay(1);
$runCount++;
return $retValue;
};
yield from $this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
public function run(): \Generator
public function run()
{
yield delay(1);
delay(1);
$this->runCount++;
return $this->retValue;
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
public function run(): \Generator
public function run()
{
yield delay(1);
delay(1);
$this->runCount++;
return $this->retValue;
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
}
/**
* Test promise loop.
@ -114,7 +114,7 @@ class PeriodicTest extends AsyncTestCase
*
* @dataProvider provideTrueFalse
*/
public function testPromise(bool $stopSig): \Generator
public function testPromise(bool $stopSig)
{
$runCount = 0;
$retValue = false;
@ -123,7 +123,7 @@ class PeriodicTest extends AsyncTestCase
$runCount++;
return new Success($retValue);
};
yield from $this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$this->fixtureAssertions($callable, $runCount, $retValue, $stopSig, $zis, true);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
@ -133,7 +133,7 @@ class PeriodicTest extends AsyncTestCase
return new Success($this->retValue);
}
};
yield from $this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions([$obj, 'run'], $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$obj = new class() {
public $retValue = false;
public $runCount = 0;
@ -143,7 +143,7 @@ class PeriodicTest extends AsyncTestCase
return new Success($this->retValue);
}
};
yield from $this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
$this->fixtureAssertions(\Closure::fromCallable([$obj, 'run']), $obj->runCount, $obj->retValue, $stopSig, $zisNew, false);
}
/**
* Fixture assertions for started loop.
@ -170,7 +170,7 @@ class PeriodicTest extends AsyncTestCase
*
* @return \Generator
*/
private function fixtureAssertions(callable $closure, int &$runCount, bool &$retValue, bool $stopSig, &$zis, bool $checkZis): \Generator
private function fixtureAssertions(callable $closure, int &$runCount, bool &$retValue, bool $stopSig, &$zis, bool $checkZis)
{
$loop = new class($closure, Fixtures::LOOP_NAME, 100) extends PeriodicLoop implements LoggingInterface {
use Logging;
@ -184,7 +184,7 @@ class PeriodicTest extends AsyncTestCase
$this->assertEquals(0, $runCount);
$loop->start();
yield delay(2);
delay(2);
if ($checkZis) {
$this->assertEquals($loop, $zis);
} else {
@ -194,18 +194,18 @@ class PeriodicTest extends AsyncTestCase
$this->assertEquals(1, $runCount);
yield delay(48);
delay(48);
$this->fixtureStarted($loop);
$this->assertEquals(1, $runCount);
yield delay(60);
delay(60);
$this->fixtureStarted($loop);
$this->assertEquals(2, $runCount);
$loop->resume();
yield delay(1);
delay(1);
$this->assertEquals(3, $runCount);
@ -215,7 +215,7 @@ class PeriodicTest extends AsyncTestCase
$retValue = true;
$loop->resume();
}
yield delay(1);
delay(1);
$this->assertEquals($stopSig ? 3 : 4, $runCount);
$this->assertFalse($loop->isRunning());

View File

@ -28,7 +28,7 @@ class ResumableTest extends Fixtures
*
* @dataProvider provideResumable
*/
public function testResumable(ResumableInterface $loop): \Generator
public function testResumable(ResumableInterface $loop)
{
$paused = $loop->resume(); // Returned promise will resolve on next pause
@ -36,9 +36,9 @@ class ResumableTest extends Fixtures
$this->assertTrue($loop->start());
$this->assertAfterStart($loop);
yield delay(10);
delay(10);
$this->assertTrue(self::isResolved($paused));
yield delay(100);
delay(100);
$this->assertFinal($loop);
}
@ -59,7 +59,7 @@ class ResumableTest extends Fixtures
$this->assertPreStart($loop);
$this->assertTrue($loop->start());
yield delay(1);
delay(1);
$this->assertFalse(self::isResolved($paused)); // Did not pause
// Invert the order as the afterTest assertions will begin the test anew
@ -77,11 +77,11 @@ class ResumableTest extends Fixtures
*
* @dataProvider provideResumableInterval
*/
public function testResumableForeverPremature(ResumableInterface $loop, ?int $interval, bool $deferred): \Generator
public function testResumableForeverPremature(ResumableInterface $loop, ?int $interval, bool $deferred)
{
$paused = $deferred ? $loop->resumeDefer() : $loop->resume(); // Will resolve on next pause
if ($deferred) {
yield delay(1); // Avoid resuming after starting
delay(1); // Avoid resuming after starting
}
$loop->setInterval($interval);
@ -90,17 +90,17 @@ class ResumableTest extends Fixtures
$this->assertAfterStart($loop);
yield delay(1);
delay(1);
$this->assertTrue(self::isResolved($paused)); // Did pause
$paused = $deferred ? $loop->resumeDefer() : $loop->resume();
if ($deferred) {
$this->assertAfterStart($loop);
yield delay(1);
delay(1);
}
$this->assertFinal($loop);
yield delay(1);
delay(1);
$this->assertFalse(self::isResolved($paused)); // Did not pause again
}
@ -113,11 +113,11 @@ class ResumableTest extends Fixtures
*
* @dataProvider provideResumable
*/
public function testResumableDeferOnce(ResumableInterface $loop): \Generator
public function testResumableDeferOnce(ResumableInterface $loop)
{
$paused1 = $loop->resumeDeferOnce(); // Will resolve on next pause
$paused2 = $loop->resumeDeferOnce(); // Will resolve on next pause
yield delay(1); // Avoid resuming after starting
delay(1); // Avoid resuming after starting
$loop->setInterval(10000);
$this->assertPreStart($loop);
@ -125,17 +125,17 @@ class ResumableTest extends Fixtures
$this->assertAfterStart($loop);
yield delay(1);
delay(1);
$this->assertTrue(self::isResolved($paused1)); // Did pause
$this->assertTrue(self::isResolved($paused2)); // Did pause
$paused1 = $loop->resumeDeferOnce();
$paused2 = $loop->resumeDeferOnce();
$this->assertAfterStart($loop);
yield delay(1);
delay(1);
$this->assertFinal($loop);
yield delay(1);
delay(1);
$this->assertFalse(self::isResolved($paused1)); // Did not pause again
$this->assertFalse(self::isResolved($paused2)); // Did not pause again
}
@ -163,14 +163,14 @@ class ResumableTest extends Fixtures
*
* @return \Generator
*/
public function provideResumableInterval(): \Generator
public function provideResumableInterval()
{
foreach ([true, false] as $deferred) {
foreach ([10000, null] as $interval) {
foreach ($this->provideResumable() as $params) {
$params[] = $interval;
$params[] = $deferred;
yield $params;
$params;
}
}
}

View File

@ -28,7 +28,7 @@ class SignalTest extends Fixtures
*
* @dataProvider provideSignal
*/
public function testSignal(SignalInterface $loop): \Generator
public function testSignal(SignalInterface $loop)
{
$loop->setInterval(500); // Wait 0.5 seconds before returning null
@ -59,7 +59,7 @@ class SignalTest extends Fixtures
$loop->setInterval(100); // Wait 0.1 seconds before returning null
$loop->signal(true); // Move along loop to apply new interval
yield delay(110);
delay(110);
$this->assertNull($loop->getPayload()); // Result of sleep
$loop->signal($e = new \RuntimeException('Test'));

View File

@ -55,7 +55,7 @@ trait Basic
public function loop(): Generator
{
$this->inited = true;
yield delay(100);
delay(100);
$this->ran = true;
}
/**

View File

@ -39,7 +39,7 @@ trait Resumable
public function loop(): Generator
{
$this->inited = true;
yield $this->pause($this->interval);
$this->pause($this->interval);
$this->ran = true;
}
}

View File

@ -54,9 +54,9 @@ trait Signal
*
* @return \Generator
*/
private function testGenerator(int $interval): \Generator
private function testGenerator(int $interval)
{
yield delay($interval);
delay($interval);
}
/**
* Loop implementation.
@ -68,7 +68,7 @@ trait Signal
$this->inited = true;
try {
while (true) {
$this->payload = yield $this->waitSignal($this instanceof ResumableLoopInterface ? $this->pause($this->interval) : $this->testGenerator($this->interval));
$this->payload = $this->waitSignal($this instanceof ResumableLoopInterface ? $this->pause($this->interval) : $this->testGenerator($this->interval));
}
} catch (\Throwable $e) {
$this->exception = $e;