Skip to content

Commit 245a712

Browse files
committed
formatting
1 parent ce69e55 commit 245a712

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

src/Illuminate/Http/Client/PendingRequest.php

+33-33
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PendingRequest
2626
protected $factory;
2727

2828
/**
29-
* The client instance.
29+
* The Guzzle client instance.
3030
*
3131
* @var \GuzzleHttp\Client
3232
*/
@@ -595,6 +595,27 @@ public function delete($url, $data = [])
595595
]);
596596
}
597597

598+
/**
599+
* Send a pool of asynchronous requests concurrently.
600+
*
601+
* @param callable $callback
602+
* @return array
603+
*/
604+
public function pool(callable $callback)
605+
{
606+
$results = [];
607+
608+
$requests = tap(new Pool($this->factory), $callback)->getRequests();
609+
610+
foreach ($requests as $key => $item) {
611+
$results[$key] = $item instanceof static ? $item->getPromise()->wait() : $item->wait();
612+
}
613+
614+
ksort($results);
615+
616+
return $results;
617+
}
618+
598619
/**
599620
* Send the request to the given URL.
600621
*
@@ -742,19 +763,6 @@ protected function populateResponse(Response $response)
742763
return $response;
743764
}
744765

745-
/**
746-
* Set the client instance.
747-
*
748-
* @param \GuzzleHttp\Client $client
749-
* @return $this
750-
*/
751-
public function setClient(Client $client)
752-
{
753-
$this->client = $client;
754-
755-
return $this;
756-
}
757-
758766
/**
759767
* Build the Guzzle client.
760768
*
@@ -932,33 +940,25 @@ public function async(bool $async = true)
932940
}
933941

934942
/**
935-
* Send a pool of asynchronous requests concurrently.
943+
* Retrieve the pending request promise.
936944
*
937-
* @param callable $callback
938-
* @return array
945+
* @return \GuzzleHttp\Promise\PromiseInterface|null
939946
*/
940-
public function pool(callable $callback)
947+
public function getPromise()
941948
{
942-
$results = [];
943-
944-
$requests = tap(new Pool($this->factory), $callback)->getRequests();
945-
946-
foreach ($requests as $key => $item) {
947-
$results[$key] = $item instanceof static ? $item->getPromise()->wait() : $item->wait();
948-
}
949-
950-
ksort($results);
951-
952-
return $results;
949+
return $this->promise;
953950
}
954951

955952
/**
956-
* Retrieve the pending request promise.
953+
* Set the client instance.
957954
*
958-
* @return \GuzzleHttp\Promise\PromiseInterface|null
955+
* @param \GuzzleHttp\Client $client
956+
* @return $this
959957
*/
960-
public function getPromise()
958+
public function setClient(Client $client)
961959
{
962-
return $this->promise;
960+
$this->client = $client;
961+
962+
return $this;
963963
}
964964
}

src/Illuminate/Http/Client/Pool.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(Factory $factory = null)
4444
* @param string $key
4545
* @return \Illuminate\Http\Client\PendingRequest
4646
*/
47-
public function add(string $key)
47+
public function as(string $key)
4848
{
4949
return $this->pool[$key] = $this->asyncRequest();
5050
}
@@ -56,7 +56,6 @@ public function add(string $key)
5656
*/
5757
protected function asyncRequest()
5858
{
59-
// the same client instance needs to be shared across all async requests
6059
return $this->factory->setClient($this->client)->async();
6160
}
6261

tests/Http/HttpClientTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,9 @@ public function testMultipleRequestsAreSentInThePoolWithKeys()
892892

893893
$responses = $this->factory->pool(function (Pool $pool) {
894894
return [
895-
$pool->add('test200')->get('200.com'),
896-
$pool->add('test400')->get('400.com'),
897-
$pool->add('test500')->get('500.com'),
895+
$pool->as('test200')->get('200.com'),
896+
$pool->as('test400')->get('400.com'),
897+
$pool->as('test500')->get('500.com'),
898898
];
899899
});
900900

0 commit comments

Comments
 (0)