diff --git a/lib/Loop/Driver.php b/lib/Loop/Driver.php index e78a8fd..017eb69 100644 --- a/lib/Loop/Driver.php +++ b/lib/Loop/Driver.php @@ -87,21 +87,37 @@ abstract class Driver */ public function createControl(): DriverControl { - return new DriverControl( - function () use (&$running) { - $running = true; - while ($running) { - if ($this->isEmpty()) { - return; - } - - $this->tick(); + return new class(function () use (&$running) { + $running = true; + while ($running) { + if ($this->isEmpty()) { + return; } - }, - static function () use (&$running) { - $running = false; + + $this->tick(); } - ); + }, static function () use (&$running) { + $running = false; + }) implements DriverControl { + private $run; + private $stop; + + public function __construct(callable $run, callable $stop) + { + $this->run = $run; + $this->stop = $stop; + } + + public function run() + { + ($this->run)(); + } + + public function stop() + { + ($this->stop)(); + } + }; } /** diff --git a/lib/Loop/DriverControl.php b/lib/Loop/DriverControl.php index 73c551f..bf611cb 100644 --- a/lib/Loop/DriverControl.php +++ b/lib/Loop/DriverControl.php @@ -2,24 +2,23 @@ namespace Amp\Loop; -final class DriverControl +interface DriverControl { - private $run; - private $stop; + /** + * Run the driver event loop. + * + * @return void + * + * @see Driver::run() + */ + public function run(); - public function __construct(callable $run, callable $stop) - { - $this->run = $run; - $this->stop = $stop; - } - - public function run() - { - ($this->run)(); - } - - public function stop() - { - ($this->stop)(); - } + /** + * Stop the driver event loop. + * + * @return void + * + * @see Driver::stop() + */ + public function stop(); }