Skip to content

Commit

Permalink
fix style issues and split up overly complex function into two
Browse files Browse the repository at this point in the history
  • Loading branch information
rokob committed Jul 28, 2017
1 parent d7e4c10 commit 9663bbe
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Senders/CurlSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function wait($accessToken, $max = 0)

private function maybeSendMoreBatchRequests($accessToken)
{
$max = $this->maxBatchRequests-count($this->inflightRequests);
$max = $this->maxBatchRequests - count($this->inflightRequests);
if ($max <= 0) {
return;
}
Expand Down Expand Up @@ -155,19 +155,18 @@ private function checkForCompletedRequests($accessToken)
$curlResponse = curl_multi_exec($this->multiHandle, $active);
} while ($curlResponse == CURLM_CALL_MULTI_PERFORM);
}

$this->removeFinishedRequests($accessToken);
}

private function removeFinishedRequests($accessToken)
{
while ($info = curl_multi_info_read($this->multiHandle)) {
$handle = $info['handle'];
$handleArrayKey = (int)$handle;
if (!isset($this->inflightRequests[$handleArrayKey])) {
// This should never happen, probably should fatal,
// but play it safe
curl_close($handle);
$this->maybeSendMoreBatchRequests($accessToken);
return;
if (isset($this->inflightRequests[$handleArrayKey])) {
unset($this->inflightRequests[$handleArrayKey]);
curl_multi_remove_handle($this->multiHandle, $handle);
}
unset($this->inflightRequests[$handleArrayKey]);
curl_multi_remove_handle($this->multiHandle, $handle);
curl_close($handle);
}
$this->maybeSendMoreBatchRequests($accessToken);
Expand Down

0 comments on commit 9663bbe

Please sign in to comment.