diff --git a/lib/Loop/Driver.php b/lib/Loop/Driver.php index bfd6f68..e78a8fd 100644 --- a/lib/Loop/Driver.php +++ b/lib/Loop/Driver.php @@ -77,17 +77,17 @@ abstract class Driver } /** - * Run the event loop with an explicit stop handle. + * Create a control that can be used to start and stop a specific iteration of the driver loop. * * This method is intended for {@see \Amp\Promise\wait()} only and NOT exposed as method in {@see \Amp\Loop}. * - * @return DelegateLoop + * @return DriverControl * * @see Driver::run() */ - public function delegate(): DelegateLoop + public function createControl(): DriverControl { - return new DelegateLoop( + return new DriverControl( function () use (&$running) { $running = true; while ($running) { diff --git a/lib/Loop/DelegateLoop.php b/lib/Loop/DriverControl.php similarity index 92% rename from lib/Loop/DelegateLoop.php rename to lib/Loop/DriverControl.php index 8e4fa0f..73c551f 100644 --- a/lib/Loop/DelegateLoop.php +++ b/lib/Loop/DriverControl.php @@ -2,7 +2,7 @@ namespace Amp\Loop; -final class DelegateLoop +final class DriverControl { private $run; private $stop; diff --git a/lib/Loop/TracingDriver.php b/lib/Loop/TracingDriver.php index 139ede5..d4abc6d 100644 --- a/lib/Loop/TracingDriver.php +++ b/lib/Loop/TracingDriver.php @@ -27,9 +27,9 @@ final class TracingDriver extends Driver $this->driver->run(); } - public function delegate(): DelegateLoop + public function createControl(): DriverControl { - return $this->driver->delegate(); + return $this->driver->createControl(); } public function stop() diff --git a/lib/functions.php b/lib/functions.php index f8bf0d0..49000a2 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -199,17 +199,17 @@ namespace Amp\Promise try { $driver = Loop::get(); - $delegate = $driver->delegate(); + $control = $driver->createControl(); - $promise->onResolve(static function ($e, $v) use (&$resolved, &$value, &$exception, $delegate) { - $delegate->stop(); + $promise->onResolve(static function ($e, $v) use (&$resolved, &$value, &$exception, $control) { + $control->stop(); $resolved = true; $exception = $e; $value = $v; }); - $delegate->run(); + $control->run(); } catch (\Throwable $throwable) { throw new \Error("Loop exceptionally stopped without resolving the promise", 0, $throwable); }