promise example

$request = $request->withHeader(
                    RequestSigner::SHOPWARE_SHOP_SIGNATURE,
                    (new RequestSigner())->signPayload($jsonPayload$webhook->getApp()->getAppSecret())
                );
            }

            $requests[] = $request;
        }

        if (\count($requests) > 0) {
            $pool = new Pool($this->guzzle, $requests);
            $pool->promise()->wait();
        }
    }

    /** * @param array<string> $affectedRoleIds */
    private function dispatchWebhooksToQueue(
        WebhookCollection $webhooksForEvent,
        Hookable $event,
        array $affectedRoleIds,
        string $languageId,
        
$pool = new Pool($this->client, $list[
            'concurrency' => $this->concurrency,
            'rejected' => function DTransferException $reason): void {
                if ($reason instanceof ServerException) {
                    throw new \RuntimeException(\sprintf('BAN request failed to %s failed with error: %s', $reason->getRequest()->getUri()->__toString()$reason->getMessage()), 0, $reason);
                }

                throw $reason;
            },
        ]);

        $pool->promise()->wait();
    }

    public function banAll(): void
    {
        $list = [];

        foreach ($this->entirePurge['urls'] as $url) {
            foreach ($this->hosts as $host) {
                $list[] = new Request($this->entirePurge['method']$host . $url$this->entirePurge['headers']);
            }
        }

        

        };

        $this->each = new EachPromise($requests()$config);
    }

    /** * Get promise */
    public function promise(): PromiseInterface
    {
        return $this->each->promise();
    }

    /** * Sends multiple requests concurrently and returns an array of responses * and exceptions that uses the same ordering as the provided requests. * * IMPORTANT: This method keeps every request and response in memory, and * as such, is NOT recommended when sending a large number or an * indeterminate number of requests concurrently. * * @param ClientInterface $client Client used to send the requests * @param array|\Iterator $requests Requests to send concurrently. * @param array $options Passes through the options available in * {@see \GuzzleHttp\Pool::__construct} * * @return array Returns an array containing the response or an exception * in the same order that the requests were sent. * * @throws \InvalidArgumentException if the event format is incorrect. */
$this->id = $id = self::$nextId++;
        Loop::defer(static function D) use ($request$multi$id, &$info, &$headers$canceller, &$options$onProgress, &$handle$logger, &$pause) {
            return new Coroutine(self::generateResponse($request$multi$id$info$headers$canceller$options$onProgress$handle$logger$pause));
        });

        $info['pause_handler'] = static function Dfloat $duration) use (&$throttleWatcher, &$pauseDeferred, &$pause) {
            if (null !== $throttleWatcher) {
                Loop::cancel($throttleWatcher);
            }

            $pause = $pauseDeferred->promise();

            if ($duration <= 0) {
                $deferred = $pauseDeferred;
                $pauseDeferred = new Deferred();
                $deferred->resolve();
            } else {
                $throttleWatcher = Loop::delay(ceil(1000 * $duration)static function D) use (&$pauseDeferred) {
                    $deferred = $pauseDeferred;
                    $pauseDeferred = new Deferred();
                    $deferred->resolve();
                });
            }


        $url = (string) $request->getUri();
        $this->logger?->debug(sprintf('Queueing pushed response: "%s"', $url));
        $this->pushedResponses[$authority][] = [$url$deferred$request$response[
            'proxy' => $options['proxy'],
            'bindto' => $options['bindto'],
            'local_cert' => $options['local_cert'],
            'local_pk' => $options['local_pk'],
        ]];

        return $deferred->promise();
    }
}
$pool = new Pool($this->client, $list[
            'concurrency' => $this->concurrency,
            'rejected' => function DTransferException $reason): void {
                if ($reason instanceof ServerException) {
                    throw new \RuntimeException(sprintf('BAN request failed to %s failed with error: %s', $reason->getRequest()->getUri()->__toString()$reason->getMessage()), 0, $reason);
                }

                throw $reason;
            },
        ]);

        $pool->promise()->wait();
    }

    public function ban(array $urls): void
    {
        $list = [];

        foreach ($urls as $url) {
            foreach ($this->hosts as $host) {
                $list[] = new Request('PURGE', $host . $url);
            }
        }

        
$pool = new Pool($this->client, $list[
            'concurrency' => $this->concurrency,
            'rejected' => function DTransferException $reason): void {
                if ($reason instanceof ServerException) {
                    throw new \RuntimeException(\sprintf('BAN request failed to %s failed with error: %s', $reason->getRequest()->getUri()->__toString()$reason->getMessage()), 0, $reason);
                }

                throw $reason;
            },
        ]);

        $pool->promise()->wait();
    }

    public function banAll(): void
    {
        if ($this->instanceTag !== '') {
            $this->invalidate([$this->instanceTag]);

            return;
        }

        $this->client->post(\sprintf('%s/service/%s/purge_all', self::API_URL, $this->serviceId)[
            

                'concurrency' => $concurrentRequests,
                'rejected' => function D$reason) use ($shopId$events) {
                    $events->notify('Shopware_Components_CacheWarmer_ErrorOccured');
                    $this->logger->warning(
                        'Warm up http-cache error with shopId ' . $shopId . ' ' . $reason
                    );
                },
            ]
        );

        $pool->promise()->wait();
    }

    private function getMainShopId($shopId)
    {
        return $this->connection->fetchColumn(
            'SELECT main_id FROM s_core_shops WHERE active = 1 AND id = :id',
            ['id' => (int) $shopId]
        );
    }
}

    public static function of(
        $iterable,
        callable $onFulfilled = null,
        callable $onRejected = null
    ): PromiseInterface {
        return (new EachPromise($iterable[
            'fulfilled' => $onFulfilled,
            'rejected' => $onRejected,
        ]))->promise();
    }

    /** * Like of, but only allows a certain number of outstanding promises at any * given time. * * $concurrency may be an integer or a function that accepts the number of * pending promises and returns a numeric concurrency limit value to allow * for dynamic a concurrency size. * * @param mixed $iterable * @param int|callable $concurrency * @param callable $onFulfilled * @param callable $onRejected */
Home | Imprint | This part of the site doesn't use cookies.