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:
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}.
|
||||
*
|
||||
* @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) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Amp\Loop;
|
||||
|
||||
final class DelegateLoop
|
||||
final class DriverControl
|
||||
{
|
||||
private $run;
|
||||
private $stop;
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user