From afcf214f24d8a6255223bed078b61def7125abd8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 23 Dec 2022 20:45:00 +0100 Subject: [PATCH] Update --- README.md | 2 +- examples/1. Basic/GenericLoop.php | 8 ++-- examples/1. Basic/PeriodicLoop.php | 10 ++-- examples/2. Advanced/Loop.php | 13 +++-- examples/2. Advanced/ResumableLoop.php | 10 ++-- examples/2. Advanced/ResumableSignalLoop.php | 12 ++--- examples/2. Advanced/SignalLoop.php | 11 ++--- lib/Interfaces/LoopInterface.php | 2 +- lib/Interfaces/ResumableLoopInterface.php | 2 +- lib/Traits/ResumableLoop.php | 2 +- test/GenericTest.php | 50 ++++++++++---------- test/LoopTest.php | 4 +- test/PeriodicTest.php | 48 +++++++++---------- test/ResumableTest.php | 32 ++++++------- test/SignalTest.php | 4 +- test/Traits/Basic.php | 2 +- test/Traits/Resumable.php | 2 +- test/Traits/Signal.php | 6 +-- 18 files changed, 106 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index c776760..73a22bc 100644 --- a/README.md +++ b/README.md @@ -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; diff --git a/examples/1. Basic/GenericLoop.php b/examples/1. Basic/GenericLoop.php index 5946c8e..cfebb9c 100644 --- a/examples/1. Basic/GenericLoop.php +++ b/examples/1. Basic/GenericLoop.php @@ -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); }); diff --git a/examples/1. Basic/PeriodicLoop.php b/examples/1. Basic/PeriodicLoop.php index ba434c3..adaa891 100644 --- a/examples/1. Basic/PeriodicLoop.php +++ b/examples/1. Basic/PeriodicLoop.php @@ -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); diff --git a/examples/2. Advanced/Loop.php b/examples/2. Advanced/Loop.php index 3b6a895..16411fd 100644 --- a/examples/2. Advanced/Loop.php +++ b/examples/2. Advanced/Loop.php @@ -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; } -}); + diff --git a/examples/2. Advanced/ResumableLoop.php b/examples/2. Advanced/ResumableLoop.php index b7b5e52..fce79b7 100644 --- a/examples/2. Advanced/ResumableLoop.php +++ b/examples/2. Advanced/ResumableLoop.php @@ -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(); } -}); diff --git a/examples/2. Advanced/ResumableSignalLoop.php b/examples/2. Advanced/ResumableSignalLoop.php index 7a34676..03da234 100644 --- a/examples/2. Advanced/ResumableSignalLoop.php +++ b/examples/2. Advanced/ResumableSignalLoop.php @@ -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); } -}); diff --git a/examples/2. Advanced/SignalLoop.php b/examples/2. Advanced/SignalLoop.php index 5f9f634..aa6763e 100644 --- a/examples/2. Advanced/SignalLoop.php +++ b/examples/2. Advanced/SignalLoop.php @@ -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); } -}); + diff --git a/lib/Interfaces/LoopInterface.php b/lib/Interfaces/LoopInterface.php index 489e4e3..d56f738 100644 --- a/lib/Interfaces/LoopInterface.php +++ b/lib/Interfaces/LoopInterface.php @@ -30,7 +30,7 @@ interface LoopInterface * * @return \Generator */ - public function loop(): \Generator; + public function loop(); /** * Get name of the loop. * diff --git a/lib/Interfaces/ResumableLoopInterface.php b/lib/Interfaces/ResumableLoopInterface.php index ec09073..d0a1ab5 100644 --- a/lib/Interfaces/ResumableLoopInterface.php +++ b/lib/Interfaces/ResumableLoopInterface.php @@ -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 */ diff --git a/lib/Traits/ResumableLoop.php b/lib/Traits/ResumableLoop.php index 3a75f2d..a7f19f9 100644 --- a/lib/Traits/ResumableLoop.php +++ b/lib/Traits/ResumableLoop.php @@ -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 Resolved when the loop is paused again */ diff --git a/test/GenericTest.php b/test/GenericTest.php index 4a851bd..fcc7f21 100644 --- a/test/GenericTest.php +++ b/test/GenericTest.php @@ -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()); diff --git a/test/LoopTest.php b/test/LoopTest.php index 8d30fb6..b4d0bc9 100644 --- a/test/LoopTest.php +++ b/test/LoopTest.php @@ -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); } diff --git a/test/PeriodicTest.php b/test/PeriodicTest.php index 5f0ff1b..cae5501 100644 --- a/test/PeriodicTest.php +++ b/test/PeriodicTest.php @@ -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()); diff --git a/test/ResumableTest.php b/test/ResumableTest.php index 8c010da..8ad0927 100644 --- a/test/ResumableTest.php +++ b/test/ResumableTest.php @@ -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; } } } diff --git a/test/SignalTest.php b/test/SignalTest.php index c5ae9e4..29a7a36 100644 --- a/test/SignalTest.php +++ b/test/SignalTest.php @@ -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')); diff --git a/test/Traits/Basic.php b/test/Traits/Basic.php index 53e002f..307e8f5 100644 --- a/test/Traits/Basic.php +++ b/test/Traits/Basic.php @@ -55,7 +55,7 @@ trait Basic public function loop(): Generator { $this->inited = true; - yield delay(100); + delay(100); $this->ran = true; } /** diff --git a/test/Traits/Resumable.php b/test/Traits/Resumable.php index cda946c..7121b7f 100644 --- a/test/Traits/Resumable.php +++ b/test/Traits/Resumable.php @@ -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; } } diff --git a/test/Traits/Signal.php b/test/Traits/Signal.php index 359cafa..2174442 100644 --- a/test/Traits/Signal.php +++ b/test/Traits/Signal.php @@ -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;