1
0
mirror of https://github.com/danog/file.git synced 2024-11-30 04:19:39 +01:00
file/lib/Internal/EioPoll.php
Aaron Piotrowski 8cd21e4994
Fix EioPoll destruction
The callback was holding a reference to $this. Hopefully this fixes the watcher cancellation issues.
2017-06-20 13:41:53 -05:00

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