mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
8cd21e4994
The callback was holding a reference to $this. Hopefully this fixes the watcher cancellation issues.
48 lines
927 B
PHP
48 lines
927 B
PHP
<?php
|
|
|
|
namespace Amp\File\Internal;
|
|
|
|
use Amp\Loop;
|
|
|
|
class EioPoll {
|
|
/** @var resource */
|
|
private static $stream;
|
|
|
|
/** @var string */
|
|
private $watcher;
|
|
|
|
/** @var int */
|
|
private $requests = 0;
|
|
|
|
public function __construct() {
|
|
if (!self::$stream) {
|
|
\eio_init();
|
|
self::$stream = \eio_get_event_stream();
|
|
}
|
|
|
|
$this->watcher = Loop::onReadable(self::$stream, static function () {
|
|
while (\eio_npending()) {
|
|
\eio_poll();
|
|
}
|
|
});
|
|
|
|
Loop::disable($this->watcher);
|
|
}
|
|
|
|
public function listen() {
|
|
if ($this->requests++ === 0) {
|
|
Loop::enable($this->watcher);
|
|
}
|
|
}
|
|
|
|
public function done() {
|
|
if (--$this->requests === 0) {
|
|
Loop::disable($this->watcher);
|
|
}
|
|
}
|
|
|
|
public function __destruct() {
|
|
Loop::cancel($this->watcher);
|
|
}
|
|
}
|