@@ -26,7 +26,7 @@ class PendingRequest
26
26
protected $ factory ;
27
27
28
28
/**
29
- * The client instance.
29
+ * The Guzzle client instance.
30
30
*
31
31
* @var \GuzzleHttp\Client
32
32
*/
@@ -595,6 +595,27 @@ public function delete($url, $data = [])
595
595
]);
596
596
}
597
597
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
+
598
619
/**
599
620
* Send the request to the given URL.
600
621
*
@@ -742,19 +763,6 @@ protected function populateResponse(Response $response)
742
763
return $ response ;
743
764
}
744
765
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
-
758
766
/**
759
767
* Build the Guzzle client.
760
768
*
@@ -932,33 +940,25 @@ public function async(bool $async = true)
932
940
}
933
941
934
942
/**
935
- * Send a pool of asynchronous requests concurrently .
943
+ * Retrieve the pending request promise .
936
944
*
937
- * @param callable $callback
938
- * @return array
945
+ * @return \GuzzleHttp\Promise\PromiseInterface|null
939
946
*/
940
- public function pool ( callable $ callback )
947
+ public function getPromise ( )
941
948
{
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 ;
953
950
}
954
951
955
952
/**
956
- * Retrieve the pending request promise .
953
+ * Set the client instance .
957
954
*
958
- * @return \GuzzleHttp\Promise\PromiseInterface|null
955
+ * @param \GuzzleHttp\Client $client
956
+ * @return $this
959
957
*/
960
- public function getPromise ( )
958
+ public function setClient ( Client $ client )
961
959
{
962
- return $ this ->promise ;
960
+ $ this ->client = $ client ;
961
+
962
+ return $ this ;
963
963
}
964
964
}
0 commit comments