-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathPoll.php
More file actions
45 lines (38 loc) · 871 Bytes
/
Poll.php
File metadata and controls
45 lines (38 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace React\Filesystem\Eio;
use React\EventLoop\Loop;
use React\Filesystem\PollInterface;
/**
* @internal
*/
final class Poll implements PollInterface
{
private $fd;
private \Closure $handleEvent;
private int $workInProgress = 0;
public function __construct()
{
$this->fd = EventStream::get();
$this->handleEvent = function () {
$this->handleEvent();
};
}
public function activate(): void
{
if ($this->workInProgress++ === 0) {
Loop::addReadStream($this->fd, $this->handleEvent);
}
}
private function handleEvent()
{
while (eio_npending()) {
eio_poll();
}
}
public function deactivate(): void
{
if (--$this->workInProgress <= 0) {
Loop::removeReadStream($this->fd);
}
}
}