Skip to content

Commit 7b398d0

Browse files
committed
Remove pool, as it's not available in 7 or low 8
1 parent 72f8d2b commit 7b398d0

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/Client.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
namespace Torchlight;
77

8-
use Illuminate\Http\Client\Pool;
8+
use GuzzleHttp\Promise\Promise;
9+
use Illuminate\Http\Client\PendingRequest;
910
use Illuminate\Support\Arr;
1011
use Illuminate\Support\Collection;
1112
use Illuminate\Support\Facades\Http;
@@ -43,6 +44,7 @@ public function highlight($blocks)
4344
protected function request(Collection $blocks)
4445
{
4546
$error = false;
47+
$response = [];
4648

4749
try {
4850
$response = $this->collectionOfBlocks($blocks)
@@ -100,19 +102,26 @@ protected function request(Collection $blocks)
100102

101103
protected function requestChunks($chunks)
102104
{
103-
return Http::pool(function (Pool $pool) use ($chunks) {
104-
$host = Torchlight::config('host', 'https://api.torchlight.dev');
105-
$timeout = Torchlight::config('request_timeout', 5);
106-
107-
$chunks->each(function ($blocks) use ($pool, $host, $timeout) {
108-
$pool->timeout($timeout)
105+
$host = Torchlight::config('host', 'https://api.torchlight.dev');
106+
$timeout = Torchlight::config('request_timeout', 5);
107+
108+
// Can't use Http::pool here because it's not
109+
// available in Laravel 7 and early 8.
110+
return $chunks
111+
// This first map fires all the requests.
112+
->map(function ($blocks) use ($host, $timeout) {
113+
return Http::async()
109114
->baseUrl($host)
115+
->timeout($timeout)
110116
->withToken($this->getToken())
111117
->post('highlight', [
112118
'blocks' => $this->blocksAsRequestParam($blocks)->values()->toArray(),
113119
]);
120+
})
121+
// The second one waits for them all to finish.
122+
->map(function (Promise $request) {
123+
return $request->wait();
114124
});
115-
});
116125
}
117126

118127
protected function collectionOfBlocks($blocks)

0 commit comments

Comments
 (0)