Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UvDriver.php

function UvDriver::activate

Overrides AbstractDriver::activate

File

vendor/revolt/event-loop/src/EventLoop/Driver/UvDriver.php, line 141

Class

UvDriver

Namespace

Revolt\EventLoop\Driver

Code

protected function activate(array $callbacks) : void {
    $now = $this->now();
    foreach ($callbacks as $callback) {
        $id = $callback->id;
        if ($callback instanceof StreamCallback) {
            \assert(\is_resource($callback->stream));
            $streamId = (int) $callback->stream;
            if (isset($this->streams[$streamId])) {
                $event = $this->streams[$streamId];
            }
            elseif (isset($this->events[$id])) {
                $event = $this->streams[$streamId] = $this->events[$id];
            }
            else {
                
                /** @psalm-suppress TooManyArguments */
                $event = $this->streams[$streamId] = \uv_poll_init_socket($this->handle, $callback->stream);
            }
            $eventId = (int) $event;
            $this->events[$id] = $event;
            $this->uvCallbacks[$eventId][$id] = $callback;
            $flags = 0;
            foreach ($this->uvCallbacks[$eventId] as $w) {
                \assert($w instanceof StreamCallback);
                $flags |= $w->enabled ? $this->getStreamCallbackFlags($w) : 0;
            }
            \uv_poll_start($event, $flags, $this->ioCallback);
        }
        elseif ($callback instanceof TimerCallback) {
            if (isset($this->events[$id])) {
                $event = $this->events[$id];
            }
            else {
                $event = $this->events[$id] = \uv_timer_init($this->handle);
            }
            $this->uvCallbacks[(int) $event] = [
                $callback,
            ];
            \uv_timer_start($event, (int) \min(\max(0, \ceil(($callback->expiration - $now) * 1000)), \PHP_INT_MAX), $callback->repeat ? (int) \min(\max(0, \ceil($callback->interval * 1000)), \PHP_INT_MAX) : 0, $this->timerCallback);
        }
        elseif ($callback instanceof SignalCallback) {
            if (isset($this->events[$id])) {
                $event = $this->events[$id];
            }
            else {
                
                /** @psalm-suppress TooManyArguments */
                $event = $this->events[$id] = \uv_signal_init($this->handle);
            }
            $this->uvCallbacks[(int) $event] = [
                $callback,
            ];
            
            /** @psalm-suppress TooManyArguments */
            \uv_signal_start($event, $this->signalCallback, $callback->signal);
        }
        else {
            // @codeCoverageIgnoreStart
            throw new \Error("Unknown callback type");
            // @codeCoverageIgnoreEnd
        }
    }
}
RSS feed
Powered by Drupal