wait example

$process->start(function D$type$buffer) use ($process, &$dumped$connection$data) {
            if (Process::ERR === $type) {
                $process->stop();
                $this->fail();
            } elseif ("READY\n" === $buffer) {
                $connection->write($data);
            } else {
                $dumped .= $buffer;
            }
        });

        $process->wait();

        $this->assertTrue($process->isSuccessful());
        $this->assertStringMatchesFormat(<<<'DUMP' (3) "foo" [ "timestamp" => %d.%d "foo_provider" => [ (3) "foo" ] ] %d

  public function rebuild() {
    if ($this->building) {
      throw new \RuntimeException('Recursive router rebuild detected.');
    }

    if (!$this->lock->acquire('router_rebuild')) {
      // Wait for another request that is already doing this work.       // We choose to block here since otherwise the routes might not be       // available, resulting in a 404.       $this->lock->wait('router_rebuild');
      return FALSE;
    }

    $this->building = TRUE;

    $collection = new RouteCollection();
    foreach ($this->getRouteDefinitions() as $routes) {
      // The top-level 'routes_callback' is a list of methods in controller       // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods       // should return a set of \Symfony\Component\Routing\Route objects, either       // in an associative array keyed by the route name, which will be iterated

        $this->mutex = false;
        $this->aggregate = new Promise(function D): void {
            if ($this->checkIfFinished()) {
                return;
            }
            reset($this->pending);
            // Consume a potentially fluctuating list of promises while             // ensuring that indexes are maintained (precluding array_shift).             while ($promise = current($this->pending)) {
                next($this->pending);
                $promise->wait();
                if (Is::settled($this->aggregate)) {
                    return;
                }
            }
        });

        // Clear the references when the promise is resolved.         $clearFn = function D): void {
            $this->iterable = $this->concurrency = $this->pending = null;
            $this->onFulfilled = $this->onRejected = null;
            $this->nextPendingIndex = 0;
        };
$transaction->rollBack();
        }
        Error::logException($this->logger, $e);
      }

      $this->lock->release(__FUNCTION__);
    }
    else {
      // Wait for another request that is already doing this work.       // We choose to block here since otherwise the router item may not       // be available during routing resulting in a 404.       $this->lock->wait(__FUNCTION__);
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    // Run after CachedRouteRebuildSubscriber.     $events[RoutingEvents::FINISHED][] = ['onRouterRebuild', 100];
    return $events;
  }

}


        try {
            $response = $this->sendPsr7Request($request, true);
        } catch (NetworkException $e) {
            return new HttplugPromise(new RejectedPromise($e));
        }

        $waitLoop = $this->waitLoop;

        $promise = new GuzzlePromise(static function D) use ($response$waitLoop) {
            $waitLoop->wait($response);
        }static function D) use ($response$promisePool) {
            $response->cancel();
            unset($promisePool[$response]);
        });

        $promisePool[$response] = [$request$promise];

        return new HttplugPromise($promise);
    }

    /** * Resolves pending promises that complete before the timeouts are reached. * * When $maxDuration is null and $idleTimeout is reached, promises are rejected. * * @return int The number of remaining pending promises */


        $response = $this->client->request('POST', $this->endpoint.'/_bulk', [
            'body' => $body,
            'headers' => [
                'Content-Type' => 'application/json',
            ],
        ]);

        $this->responses->attach($response);

        $this->wait(false);
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }

    /** * @return void */
    public function __wakeup()
    {

  public function doTestCreateMediaType($media_type_id$source_id, array $provided_fields = []$source_label_visibility = 'visually_hidden') {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $media_type_id);
    $this->getSession()
      ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

    // Make sure the source is available.     $assert_session->fieldExists('Media source');
    $assert_session->optionExists('Media source', $source_id);
    $page->selectFieldOption('Media source', $source_id);
    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
    $this->assertNotEmpty($result);

    // Make sure the provided fields are visible on the form.     foreach ($provided_fields as $provided_field) {
      $result = $assert_session->waitForElementVisible('css', 'select[name="field_map[' . $provided_field . ']"]');
      

    public static function inspect(PromiseInterface $promise): array
    {
        try {
            return [
                'state' => PromiseInterface::FULFILLED,
                'value' => $promise->wait(),
            ];
        } catch (RejectionException $e) {
            return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()];
        } catch (\Throwable $e) {
            return ['state' => PromiseInterface::REJECTED, 'reason' => $e];
        }
    }

    /** * Waits on all of the provided promises, but does not unwrap rejected * promises as thrown exception. * * Returns an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param PromiseInterface[] $promises Traversable of promises to wait upon. */
$guzzlePromise = new Promise(function D) use (&$guzzlePromise$result) {
                $guzzlePromise->resolve($result);
            });

            return new HttplugPromise($guzzlePromise);
        };

        $promise1 = $mkPromise('result');
        $promise2 = $promise1->then($mkPromise);
        $promise3 = $promise2->then(fn ($result) => $result);

        $this->assertSame('result', $promise3->wait());
    }
}
$successCallableCalled = true;

            return $response;
        }function D\Exception $exception) use (&$failureCallableCalled) {
            $failureCallableCalled = true;

            throw $exception;
        });

        $this->assertEquals(Promise::PENDING, $promise->getState());

        $response = $promise->wait(true);
        $this->assertTrue($successCallableCalled, '$promise->then() was never called.');
        $this->assertFalse($failureCallableCalled, 'Failure callable should not be called when request is successful.');
        $this->assertEquals(Promise::FULFILLED, $promise->getState());

        $this->assertSame(200, $response->getStatusCode());
        $this->assertSame('application/json', $response->getHeaderLine('content-type'));

        $body = json_decode((string) $response->getBody(), true);

        $this->assertSame('HTTP/1.1', $body['SERVER_PROTOCOL']);
    }

    
      // tempstore data. Note this has to be done before the key is created as       // the owner is used in key creation.       $this->startSession();
      $session = $this->requestStack->getCurrentRequest()->getSession();
      if (!$session->has('core.tempstore.private.owner')) {
        $session->set('core.tempstore.private.owner', Crypt::randomBytesBase64());
      }
    }

    $key = $this->createkey($key);
    if (!$this->lockBackend->acquire($key)) {
      $this->lockBackend->wait($key);
      if (!$this->lockBackend->acquire($key)) {
        throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage.");
      }
    }

    $value = (object) [
      'owner' => $this->getOwner(),
      'data' => $value,
      'updated' => (int) $this->requestStack->getMainRequest()->server->get('REQUEST_TIME'),
    ];
    $this->storage->setWithExpire($key$value$this->expire);
    

  protected function tearDown(): void {
    if ($this->mink) {
      $status = $this->getStatus();
      if ($status === BaseTestRunner::STATUS_ERROR || $status === BaseTestRunner::STATUS_WARNING || $status === BaseTestRunner::STATUS_FAILURE) {
        // Ensure we capture the output at point of failure.         @$this->htmlOutput();
      }
      // Wait for all requests to finish. It is possible that an AJAX request is       // still on-going.       $result = $this->getSession()->wait(5000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))');
      if (!$result) {
        // If the wait is unsuccessful, there may still be an AJAX request in         // progress. If we tear down now, then this AJAX request may fail with         // missing database tables, because tear down will have removed them.         // Rather than allow it to fail, throw an explicit exception now         // explaining what the problem is.         throw new \RuntimeException('Unfinished AJAX requests while tearing down a test');
      }

      $warnings = $this->getSession()->evaluateScript("JSON.parse(sessionStorage.getItem('js_testing_log_test.warnings') || JSON.stringify([]))");
      foreach ($warnings as $warning) {
        
/** * @var Promise */
    private $result;

    public function __construct(callable $generatorFn)
    {
        $this->generator = $generatorFn();
        $this->result = new Promise(function D): void {
            while (isset($this->currentPromise)) {
                $this->currentPromise->wait();
            }
        });
        try {
            $this->nextCoroutine($this->generator->current());
        } catch (Throwable $throwable) {
            $this->result->reject($throwable);
        }
    }

    /** * Create a new coroutine. */

        public function schemaDefinition()
        {
            return $this->lazyLoadItself()->schemaDefinition();
        }

        /** * {@inheritdoc} */
        public function wait($name$delay = 30)
        {
            return $this->lazyLoadItself()->wait($name$delay);
        }

        /** * {@inheritdoc} */
        public function getLockId()
        {
            return $this->lazyLoadItself()->getLockId();
        }

    }

}

        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->unwatch(...\func_get_args());
    }

    public function watch($key, ...$other_keys): \Redis|bool
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->watch(...\func_get_args());
    }

    public function wait($numreplicas$timeout): false|int
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->wait(...\func_get_args());
    }

    public function xack($key$group$ids): false|int
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->xack(...\func_get_args());
    }

    public function xadd($key$id$values$maxlen = 0, $approx = false, $nomkstream = false): \Redis|false|string
    {
        return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->xadd(...\func_get_args());
    }

    
Home | Imprint | This part of the site doesn't use cookies.