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;
}