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

Breadcrumb

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

function AbstractDriver::createCallbackFiber

2 calls to AbstractDriver::createCallbackFiber()
AbstractDriver::invokeCallbacks in vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php
AbstractDriver::__construct in vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php

File

vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php, line 558

Class

AbstractDriver
Event loop driver which implements all basic operations to allow interoperability.

Namespace

Revolt\EventLoop\Internal

Code

private function createCallbackFiber() : void {
    $this->callbackFiber = new \Fiber(function () : void {
        do {
            $this->invokeMicrotasks();
            while (!$this->callbackQueue
                ->isEmpty()) {
                
                /** @var DriverCallback $callback */
                $callback = $this->callbackQueue
                    ->dequeue();
                if (!isset($this->callbacks[$callback->id]) || !$callback->invokable) {
                    unset($callback);
                    continue;
                }
                if ($callback instanceof DeferCallback) {
                    $this->cancel($callback->id);
                }
                elseif ($callback instanceof TimerCallback) {
                    if (!$callback->repeat) {
                        $this->cancel($callback->id);
                    }
                    else {
                        // Disable and re-enable, so it's not executed repeatedly in the same tick
                        // See https://github.com/amphp/amp/issues/131
                        $this->disable($callback->id);
                        $this->enable($callback->id);
                    }
                }
                try {
                    $result = match (true) {    $callback instanceof StreamCallback => ($callback->closure)($callback->id, $callback->stream),
                        $callback instanceof SignalCallback => ($callback->closure)($callback->id, $callback->signal),
                        default => ($callback->closure)($callback->id),
                    
                    };
                    if ($result !== null) {
                        throw InvalidCallbackError::nonNullReturn($callback->id, $callback->closure);
                    }
                } catch (\Throwable $exception) {
                    $this->error($callback->closure, $exception);
                } finally {
                    FiberLocal::clear();
                }
                unset($callback);
                if ($this->interrupt) {
                    
                    /** @noinspection PhpUnhandledExceptionInspection */
                    \Fiber::suspend($this->internalSuspensionMarker);
                }
                $this->invokeMicrotasks();
            }
            
            /** @noinspection PhpUnhandledExceptionInspection */
            \Fiber::suspend($this->internalSuspensionMarker);
        } while (true);
    });
}

API Navigation

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