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

Breadcrumb

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

function EventDriver::activate

Overrides AbstractDriver::activate

File

vendor/revolt/event-loop/src/EventLoop/Driver/EventDriver.php, line 167

Class

EventDriver

Namespace

Revolt\EventLoop\Driver

Code

protected function activate(array $callbacks) : void {
    $now = $this->now();
    foreach ($callbacks as $callback) {
        if (!isset($this->events[$id = $callback->id])) {
            if ($callback instanceof StreamReadableCallback) {
                \assert(\is_resource($callback->stream));
                $this->events[$id] = new \Event($this->handle, $callback->stream, \Event::READ | \Event::PERSIST, $this->ioCallback, $callback);
            }
            elseif ($callback instanceof StreamWritableCallback) {
                \assert(\is_resource($callback->stream));
                $this->events[$id] = new \Event($this->handle, $callback->stream, \Event::WRITE | \Event::PERSIST, $this->ioCallback, $callback);
            }
            elseif ($callback instanceof TimerCallback) {
                $this->events[$id] = new \Event($this->handle, -1, \Event::TIMEOUT, $this->timerCallback, $callback);
            }
            elseif ($callback instanceof SignalCallback) {
                $this->events[$id] = new \Event($this->handle, $callback->signal, \Event::SIGNAL | \Event::PERSIST, $this->signalCallback, $callback);
            }
            else {
                // @codeCoverageIgnoreStart
                throw new \Error("Unknown callback type");
                // @codeCoverageIgnoreEnd
            }
        }
        if ($callback instanceof TimerCallback) {
            $interval = \min(\max(0, $callback->expiration - $now), \PHP_INT_MAX / 2);
            $this->events[$id]
                ->add($interval > 0 ? $interval : 0);
        }
        elseif ($callback instanceof SignalCallback) {
            $this->signals[$id] = $this->events[$id];
            
            /** @psalm-suppress TooFewArguments https://github.com/JetBrains/phpstorm-stubs/pull/763 */
            $this->events[$id]
                ->add();
        }
        else {
            
            /** @psalm-suppress TooFewArguments https://github.com/JetBrains/phpstorm-stubs/pull/763 */
            $this->events[$id]
                ->add();
        }
    }
}
RSS feed
Powered by Drupal