Interop\Async\Loop\Driver::defer PHP Method

defer() abstract public method

The deferred callable MUST be executed in the next tick of the event loop and before any other type of watcher. Order of enabling MUST be preserved when executing the callbacks.
abstract public defer ( callable $callback, mixed $data = null ) : string
$callback callable
$data mixed Arbitrary data given to the callback function as the `$data` parameter.
return string An unique identifier that can be used to cancel, enable or disable the watcher.
    public abstract function defer(callable $callback, $data = null);

Usage Example

Ejemplo n.º 1
0
 /**
  * Execute a callback within the scope of an event loop driver.
  *
  * @param callable $callback The callback to execute.
  * @param Driver $driver The event loop driver. If `null`, a new one is created from the set factory.
  *
  * @return void
  *
  * @see \Interop\Async\Loop::setFactory()
  */
 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--;
     }
 }