Interop\Async\Loop::execute PHP Метод

execute() публичный статический Метод

The loop MUST continue to run until it is either stopped explicitly, no referenced watchers exist anymore, or an exception is thrown that cannot be handled. Exceptions that cannot be handled are exceptions thrown from an error handler or exceptions that would be passed to an error handler but none exists to handle them.
См. также: Interop\Async\Loop::setFactory()
public static execute ( callable $callback, Driver $driver = null ) : void
$callback callable The callback to execute.
$driver Interop\Async\Loop\Driver The event loop driver. If `null`, a new one is created from the set factory.
Результат void
    public static function execute(callable $callback, Driver $driver = null)
    {
        $previousDriver = self::$driver;
        self::$driver = $driver ?: self::createDriver();
        self::$level++;
        try {
            self::$driver->defer($callback);
            self::$driver->run();
        } finally {
            self::$driver = $previousDriver;
            self::$level--;
        }
    }

Usage Example

Пример #1
0
 /** @test */
 public function executeStackReturnsScopedDriver()
 {
     $driver1 = new DummyDriver();
     $driver2 = new DummyDriver();
     Loop::execute(function () use($driver1, $driver2) {
         $this->assertSame($driver1, Loop::get());
         Loop::execute(function () use($driver2) {
             $this->assertSame($driver2, Loop::get());
         }, $driver2);
         $this->assertSame($driver1, Loop::get());
     }, $driver1);
 }
All Usage Examples Of Interop\Async\Loop::execute