1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 12:24:40 +01:00

Use Events::setBlocking() added to parallel extension

This commit is contained in:
Aaron Piotrowski 2019-05-01 12:08:52 -05:00
parent 7303b8dcf3
commit 2d02d964f4
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -26,20 +26,16 @@ class ParallelHub extends ProcessHub
parent::__construct();
$events = $this->events = new Events;
$this->events->setTimeout(0);
$this->events->setBlocking(false);
$channels = &$this->channels;
$this->watcher = Loop::repeat(self::EXIT_CHECK_FREQUENCY, static function () use (&$channels, $events): void {
try {
while ($event = $events->poll()) {
$id = (int) $event->source;
\assert(isset($channels[$id]), 'Channel for context ID not found');
$channel = $channels[$id];
unset($channels[$id]);
$channel->close();
}
} catch (Timeout $exception) {
// Ignore poll timeout.
while ($event = $events->poll()) {
$id = (int) $event->source;
\assert(isset($channels[$id]), 'Channel for context ID not found');
$channel = $channels[$id];
unset($channels[$id]);
$channel->close();
}
});
Loop::disable($this->watcher);