Interop\Async\Loop::delay PHP Method

delay() public static method

The delay is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be determined by which timers expire first, but timers with the same expiration time MAY be executed in any order.
public static delay ( $time, 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 static function delay($time, callable $callback, $data = null)
    {
        $driver = self::$driver ?: self::get();
        return $driver->delay($time, $callback, $data);
    }

Usage Example

Beispiel #1
0
 protected function pollFilesystem()
 {
     if (empty($this->watchers)) {
         return;
     }
     $watchers = [];
     foreach ($this->watchers as $id => list($path, $events, $callback)) {
         $sync = $this->pool->invokeStaticMethod(static::class, 'collectStats', $path);
         $sync->when(function ($e, $v = null) use($id, $path, $events, $callback) {
             if (!$e) {
                 try {
                     if (isset($this->state[$id])) {
                         $this->triggerEvents($id, $this->state[$id], $v, $events, $callback);
                     }
                 } finally {
                     $this->state[$id] = $v;
                 }
             }
         });
         $watchers[] = $sync;
     }
     $await = new AwaitPending($watchers);
     $await->when(function () {
         $this->timer = Loop::delay($this->interval, function () {
             $this->pollFilesystem();
         });
     });
     return $await;
 }
All Usage Examples Of Interop\Async\Loop::delay