public function pollForCertificate(string $location): Promise {
        return call(function () use ($location) {
            do {
                /** @var Response $response */
                $response = yield $this->acmeClient->get($location);

                if ($response->getStatus() === 202) {
                    if (!$response->hasHeader('retry-after')) {
                        // throw new AcmeException("Protocol Violation: No Retry-After Header!");

                        yield new Delayed(1000);
                        continue;
                    }

                    $waitTime = $this->parseRetryAfter($response->getHeader('retry-after'));
                    $waitTime = min(max($waitTime, 2), 60);

                    yield new Delayed($waitTime * 1000);

                    continue;
                }

                if ($response->getStatus() === 200) {
                    $pem = chunk_split(base64_encode(yield $response->getBody()), 64, "\n");
                    $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n";

                    $certificates = [
                        $pem,
                    ];

                    // prevent potential infinite loop
                    $maximumChainLength = 5;

                    while ($response->hasHeader('link')) {
                        if (!$maximumChainLength--) {
                            throw new AcmeException('Too long certificate chain');
                        }

                        $links = $response->getHeaderArray('link');

                        foreach ($links as $link) {
                            if (preg_match('#<(.*?)>;rel="up"#x', $link, $match)) {
                                $uri = \Sabre\Uri\resolve($response->getRequest()->getUri(), $match[1]);
                                $response = yield $this->acmeClient->get($uri);

                                $pem = chunk_split(base64_encode(yield $response->getBody()), 64, "\n");
                                $pem = "-----BEGIN CERTIFICATE-----\n" . $pem . "-----END CERTIFICATE-----\n";
                                $certificates[] = $pem;
                            }
                        }
                    }

                    return $certificates;
                }
            } while (1);

            throw new AcmeException("Couldn't fetch certificate");
        });
    }