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
RevoltCode
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;
}
}