Skip to content

Commit

Permalink
Changed retryAsync() code to be simpler thanks to Porter improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Apr 19, 2018
1 parent 1bb5036 commit 4e8fde7
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/AsyncHttpConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,18 @@ public function fetchAsync(ConnectionContext $context, string $source): Promise

return $context->retryAsync(
static function () use ($client, $source) {
return \Amp\call(
static function () use ($client, $source) {
try {
/** @var Response $response */
$response = yield $client->request($source);
// Retry HTTP timeouts, socket timeouts and DNS resolution errors.
} catch (TimeoutException | SocketException | DnsException $exception) {
// Convert exception to recoverable exception.
throw new HttpConnectionException(
$exception->getMessage(),
$exception->getCode(),
$exception
);
}

$body = yield $response->getBody();

return HttpResponse::fromArtaxResponse($response, $body);
}
);
try {
/** @var Response $response */
$response = yield $client->request($source);
// Retry HTTP timeouts, socket timeouts and DNS resolution errors.
} catch (TimeoutException | SocketException | DnsException $exception) {
// Convert exception to recoverable exception.
throw new HttpConnectionException($exception->getMessage(), $exception->getCode(), $exception);
}

$body = yield $response->getBody();

return HttpResponse::fromArtaxResponse($response, $body);
}
);
});
Expand Down

0 comments on commit 4e8fde7

Please sign in to comment.