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

Breadcrumb

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

class Loop

@author Jordi Boggiano <j.boggiano@seld.be>

Hierarchy

  • class \Composer\Util\Loop

Expanded class hierarchy of Loop

6 files declare their use of Loop
ArchiveCommand.php in vendor/composer/composer/src/Composer/Command/ArchiveCommand.php
ArchiveManager.php in vendor/composer/composer/src/Composer/Package/Archiver/ArchiveManager.php
ComposerRepository.php in vendor/composer/composer/src/Composer/Repository/ComposerRepository.php
Factory.php in vendor/composer/composer/src/Composer/Factory.php
InstallationManager.php in vendor/composer/composer/src/Composer/Installer/InstallationManager.php

... See full list

7 string references to 'Loop'
file.schema.yml in core/modules/file/config/schema/file.schema.yml
core/modules/file/config/schema/file.schema.yml
FileMediaFormatterBase::prepareAttributes in core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
Prepare the attributes according to the settings.
FileMediaFormatterBase::settingsForm in core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
Returns a form to configure settings for the formatter.
FileMediaFormatterBase::settingsForm in core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
Returns a form to configure settings for the formatter.
FileMediaFormatterBase::settingsSummary in core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php
Returns a short summary for the current formatter settings.

... See full list

File

vendor/composer/composer/src/Composer/Util/Loop.php, line 22

Namespace

Composer\Util
View source
class Loop {
    
    /** @var HttpDownloader */
    private $httpDownloader;
    
    /** @var ProcessExecutor|null */
    private $processExecutor;
    
    /** @var array<int, array<PromiseInterface<mixed>>> */
    private $currentPromises = [];
    
    /** @var int */
    private $waitIndex = 0;
    public function __construct(HttpDownloader $httpDownloader, ?ProcessExecutor $processExecutor = null) {
        $this->httpDownloader = $httpDownloader;
        $this->httpDownloader
            ->enableAsync();
        $this->processExecutor = $processExecutor;
        if ($this->processExecutor) {
            $this->processExecutor
                ->enableAsync();
        }
    }
    public function getHttpDownloader() : HttpDownloader {
        return $this->httpDownloader;
    }
    public function getProcessExecutor() : ?ProcessExecutor {
        return $this->processExecutor;
    }
    
    /**
     * @param array<PromiseInterface<mixed>> $promises
     * @param ProgressBar|null              $progress
     */
    public function wait(array $promises, ?ProgressBar $progress = null) : void {
        $uncaught = null;
        \React\Promise\all($promises)->then(static function () : void {
        }, static function (\Throwable $e) use (&$uncaught) : void {
            $uncaught = $e;
        });
        // keep track of every group of promises that is waited on, so abortJobs can
        // cancel them all, even if wait() was called within a wait()
        $waitIndex = $this->waitIndex++;
        $this->currentPromises[$waitIndex] = $promises;
        if ($progress) {
            $totalJobs = 0;
            $totalJobs += $this->httpDownloader
                ->countActiveJobs();
            if ($this->processExecutor) {
                $totalJobs += $this->processExecutor
                    ->countActiveJobs();
            }
            $progress->start($totalJobs);
        }
        $lastUpdate = 0;
        while (true) {
            $activeJobs = 0;
            $activeJobs += $this->httpDownloader
                ->countActiveJobs();
            if ($this->processExecutor) {
                $activeJobs += $this->processExecutor
                    ->countActiveJobs();
            }
            if ($progress && microtime(true) - $lastUpdate > 0.1) {
                $lastUpdate = microtime(true);
                $progress->setProgress($progress->getMaxSteps() - $activeJobs);
            }
            if (!$activeJobs) {
                break;
            }
        }
        // as we skip progress updates if they are too quick, make sure we do one last one here at 100%
        if ($progress) {
            $progress->finish();
        }
        unset($this->currentPromises[$waitIndex]);
        if (null !== $uncaught) {
            throw $uncaught;
        }
    }
    public function abortJobs() : void {
        foreach ($this->currentPromises as $promiseGroup) {
            foreach ($promiseGroup as $promise) {
                // to support react/promise 2.x we wrap the promise in a resolve() call for safety
                \React\Promise\resolve($promise)->cancel();
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
Loop::$currentPromises private property @var array&lt;int, array&lt;PromiseInterface&lt;mixed&gt;&gt;&gt;
Loop::$httpDownloader private property @var HttpDownloader
Loop::$processExecutor private property @var ProcessExecutor|null
Loop::$waitIndex private property @var int
Loop::abortJobs public function
Loop::getHttpDownloader public function
Loop::getProcessExecutor public function
Loop::wait public function
Loop::__construct public function

API Navigation

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