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

Breadcrumb

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

function UvDriver::__construct

Overrides AbstractDriver::__construct

File

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

Class

UvDriver

Namespace

Revolt\EventLoop\Driver

Code

public function __construct() {
    parent::__construct();
    $this->handle = \uv_loop_new();
    $this->ioCallback = function ($event, $status, $events, $resource) : void {
        $callbacks = $this->uvCallbacks[(int) $event];
        // Invoke the callback on errors, as this matches behavior with other loop back-ends.
        // Re-enable callback as libuv disables the callback on non-zero status.
        if ($status !== 0) {
            $flags = 0;
            foreach ($callbacks as $callback) {
                \assert($callback instanceof StreamCallback);
                $flags |= $callback->invokable ? $this->getStreamCallbackFlags($callback) : 0;
            }
            \uv_poll_start($event, $flags, $this->ioCallback);
        }
        foreach ($callbacks as $callback) {
            \assert($callback instanceof StreamCallback);
            // $events is ORed with 4 to trigger callback if no events are indicated (0) or on UV_DISCONNECT (4).
            // http://docs.libuv.org/en/v1.x/poll.html
            if (!($this->getStreamCallbackFlags($callback) & $events || ($events | 4) === 4)) {
                continue;
            }
            $this->enqueueCallback($callback);
        }
    };
    $this->timerCallback = function ($event) : void {
        $callback = $this->uvCallbacks[(int) $event][0];
        \assert($callback instanceof TimerCallback);
        $this->enqueueCallback($callback);
    };
    $this->signalCallback = function ($event) : void {
        $callback = $this->uvCallbacks[(int) $event][0];
        $this->enqueueCallback($callback);
    };
}
RSS feed
Powered by Drupal