mirror of
https://github.com/danog/amp.git
synced 2024-12-04 10:28:01 +01:00
Rename to DriverControl
This commit is contained in:
parent
702aee45d3
commit
ab409bb254
@ -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}.
|
* 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()
|
* @see Driver::run()
|
||||||
*/
|
*/
|
||||||
public function delegate(): DelegateLoop
|
public function createControl(): DriverControl
|
||||||
{
|
{
|
||||||
return new DelegateLoop(
|
return new DriverControl(
|
||||||
function () use (&$running) {
|
function () use (&$running) {
|
||||||
$running = true;
|
$running = true;
|
||||||
while ($running) {
|
while ($running) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Amp\Loop;
|
namespace Amp\Loop;
|
||||||
|
|
||||||
final class DelegateLoop
|
final class DriverControl
|
||||||
{
|
{
|
||||||
private $run;
|
private $run;
|
||||||
private $stop;
|
private $stop;
|
@ -27,9 +27,9 @@ final class TracingDriver extends Driver
|
|||||||
$this->driver->run();
|
$this->driver->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delegate(): DelegateLoop
|
public function createControl(): DriverControl
|
||||||
{
|
{
|
||||||
return $this->driver->delegate();
|
return $this->driver->createControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop()
|
public function stop()
|
||||||
|
@ -199,17 +199,17 @@ namespace Amp\Promise
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$driver = Loop::get();
|
$driver = Loop::get();
|
||||||
$delegate = $driver->delegate();
|
$control = $driver->createControl();
|
||||||
|
|
||||||
$promise->onResolve(static function ($e, $v) use (&$resolved, &$value, &$exception, $delegate) {
|
$promise->onResolve(static function ($e, $v) use (&$resolved, &$value, &$exception, $control) {
|
||||||
$delegate->stop();
|
$control->stop();
|
||||||
|
|
||||||
$resolved = true;
|
$resolved = true;
|
||||||
$exception = $e;
|
$exception = $e;
|
||||||
$value = $v;
|
$value = $v;
|
||||||
});
|
});
|
||||||
|
|
||||||
$delegate->run();
|
$control->run();
|
||||||
} catch (\Throwable $throwable) {
|
} catch (\Throwable $throwable) {
|
||||||
throw new \Error("Loop exceptionally stopped without resolving the promise", 0, $throwable);
|
throw new \Error("Loop exceptionally stopped without resolving the promise", 0, $throwable);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user