@@ -72,9 +72,12 @@ public function start(Run $run): void
72
72
73
73
private function work (Run $ run ): void
74
74
{
75
+ $ onFulfilled = fn (Response $ response ) => $ this ->onFulfilled ($ response );
76
+ $ onRejected = fn (\Throwable $ exception , Request $ request ) => $ this ->onRejected ($ exception , $ request );
77
+
75
78
while (!$ this ->scheduler ->empty ()) {
76
79
foreach ($ this ->scheduler ->nextRequests ($ run ->concurrency ) as $ request ) {
77
- $ this ->downloader ->prepare ($ request );
80
+ $ this ->downloader ->prepare ($ request, $ onRejected );
78
81
}
79
82
80
83
// It's possible that requests were dropped while sending them through the
@@ -94,15 +97,13 @@ private function work(Run $run): void
94
97
$ difference = $ run ->concurrency - $ scheduledRequests ;
95
98
96
99
foreach ($ this ->scheduler ->forceNextRequests ($ difference ) as $ request ) {
97
- $ this ->downloader ->prepare ($ request );
100
+ $ this ->downloader ->prepare ($ request, $ onRejected );
98
101
}
99
102
100
103
$ scheduledRequests = $ this ->downloader ->scheduledRequests ();
101
104
}
102
105
103
- $ this ->downloader ->flush (
104
- fn (Response $ response ) => $ this ->onFulfilled ($ response ),
105
- );
106
+ $ this ->downloader ->flush ($ onFulfilled , $ onRejected );
106
107
}
107
108
108
109
$ this ->eventDispatcher ->dispatch (
@@ -125,6 +126,11 @@ private function onFulfilled(Response $response): void
125
126
}
126
127
}
127
128
129
+ private function onRejected (\Throwable $ exception , Request $ request ): void
130
+ {
131
+ throw $ exception ;
132
+ }
133
+
128
134
private function scheduleRequest (Request $ request ): void
129
135
{
130
136
$ this ->eventDispatcher ->dispatch (
0 commit comments