Skip to content

Commit 3f564ee

Browse files
committed
Add on rejected callback to downloader in engine
1 parent 2013b0d commit 3f564ee

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Core/Engine.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ public function start(Run $run): void
7272

7373
private function work(Run $run): void
7474
{
75+
$onFulfilled = fn (Response $response) => $this->onFulfilled($response);
76+
$onRejected = fn (\Throwable $exception, Request $request) => $this->onRejected($exception, $request);
77+
7578
while (!$this->scheduler->empty()) {
7679
foreach ($this->scheduler->nextRequests($run->concurrency) as $request) {
77-
$this->downloader->prepare($request);
80+
$this->downloader->prepare($request, $onRejected);
7881
}
7982

8083
// It's possible that requests were dropped while sending them through the
@@ -94,15 +97,13 @@ private function work(Run $run): void
9497
$difference = $run->concurrency - $scheduledRequests;
9598

9699
foreach ($this->scheduler->forceNextRequests($difference) as $request) {
97-
$this->downloader->prepare($request);
100+
$this->downloader->prepare($request, $onRejected);
98101
}
99102

100103
$scheduledRequests = $this->downloader->scheduledRequests();
101104
}
102105

103-
$this->downloader->flush(
104-
fn (Response $response) => $this->onFulfilled($response),
105-
);
106+
$this->downloader->flush($onFulfilled, $onRejected);
106107
}
107108

108109
$this->eventDispatcher->dispatch(
@@ -125,6 +126,11 @@ private function onFulfilled(Response $response): void
125126
}
126127
}
127128

129+
private function onRejected(\Throwable $exception, Request $request): void
130+
{
131+
throw $exception;
132+
}
133+
128134
private function scheduleRequest(Request $request): void
129135
{
130136
$this->eventDispatcher->dispatch(

0 commit comments

Comments
 (0)