1
0
mirror of https://github.com/danog/amp.git synced 2024-12-03 09:57:51 +01:00

Rename to DriverControl

This commit is contained in:
Aaron Piotrowski 2020-04-16 10:59:02 -05:00
parent 702aee45d3
commit ab409bb254
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
4 changed files with 11 additions and 11 deletions

View File

@ -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) {

View File

@ -2,7 +2,7 @@
namespace Amp\Loop;
final class DelegateLoop
final class DriverControl
{
private $run;
private $stop;

View File

@ -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()

View File

@ -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);
}