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

Breadcrumb

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

function EventLoop::setDriver

Sets the driver to be used as the event loop.

1 call to EventLoop::setDriver()
EventLoop::getDriver in vendor/revolt/event-loop/src/EventLoop.php
Retrieve the event loop driver that is in scope.

File

vendor/revolt/event-loop/src/EventLoop.php, line 28

Class

EventLoop
Accessor to allow global access to the event loop.

Namespace

Revolt

Code

public static function setDriver(Driver $driver) : void {
    
    /** @psalm-suppress RedundantPropertyInitializationCheck, RedundantCondition */
    if (isset(self::$driver) && self::$driver->isRunning()) {
        throw new \Error("Can't swap the event loop driver while the driver is running");
    }
    try {
        
        /** @psalm-suppress InternalClass */
        self::$driver = new class  extends AbstractDriver {
            protected function activate(array $callbacks) : void {
                throw new \Error("Can't activate callback during garbage collection.");
            }
            protected function dispatch(bool $blocking) : void {
                throw new \Error("Can't dispatch during garbage collection.");
            }
            protected function deactivate(DriverCallback $callback) : void {
                // do nothing
            }
            public function getHandle() : mixed {
                return null;
            }
            protected function now() : float {
                return (double) \hrtime(true) / 1000000000;
            }

};
        \gc_collect_cycles();
    } finally {
        self::$driver = $driver;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal