mirror of
https://github.com/danog/amp.git
synced 2024-12-02 17:37:50 +01:00
Make DriverControl an interface
This commit is contained in:
parent
ab409bb254
commit
0eb8ef438e
@ -87,8 +87,7 @@ abstract class Driver
|
||||
*/
|
||||
public function createControl(): DriverControl
|
||||
{
|
||||
return new DriverControl(
|
||||
function () use (&$running) {
|
||||
return new class(function () use (&$running) {
|
||||
$running = true;
|
||||
while ($running) {
|
||||
if ($this->isEmpty()) {
|
||||
@ -97,11 +96,28 @@ abstract class Driver
|
||||
|
||||
$this->tick();
|
||||
}
|
||||
},
|
||||
static function () use (&$running) {
|
||||
}, 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)();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user