File tree 3 files changed +52
-5
lines changed
3 files changed +52
-5
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,10 @@ public function enqueue(callable $task): void
19
19
private function drain (): void
20
20
{
21
21
for ($ i = \key ($ this ->queue ); isset ($ this ->queue [$ i ]); $ i ++) {
22
- try {
23
- ($ this ->queue [$ i ])();
24
- } finally {
25
- unset($ this ->queue [$ i ]);
26
- }
22
+ $ task = $ this ->queue [$ i ];
23
+ unset($ this ->queue [$ i ]);
24
+
25
+ $ task ();
27
26
}
28
27
29
28
$ this ->queue = [];
Original file line number Diff line number Diff line change @@ -30,6 +30,27 @@ public function executesNestedEnqueuedTasks()
30
30
$ queue ->enqueue ($ task );
31
31
}
32
32
33
+ /**
34
+ * @test
35
+ * @requires PHP 8.1
36
+ */
37
+ public function executesFollowingTasksIfPriorTaskSuspendsFiber ()
38
+ {
39
+ $ queue = new Queue ();
40
+
41
+ $ fiber = new \Fiber (function () use ($ queue ) {
42
+ $ queue ->enqueue (function () {
43
+ \Fiber::suspend (2 );
44
+ });
45
+ return 1 ;
46
+ });
47
+
48
+ $ ret = $ fiber ->start ();
49
+ $ this ->assertEquals (2 , $ ret );
50
+
51
+ $ queue ->enqueue ($ this ->expectCallableOnce ());
52
+ }
53
+
33
54
/**
34
55
* @test
35
56
*/
Original file line number Diff line number Diff line change @@ -184,6 +184,33 @@ public function thenShouldSwitchFromCallbacksToErrbacksWhenCallbackThrows()
184
184
);
185
185
}
186
186
187
+ /**
188
+ * @test
189
+ * @requires PHP 8.1
190
+ */
191
+ public function thenShouldContinueToExecuteCallbacksWhenPriorCallbackSuspendsFiber ()
192
+ {
193
+ $ adapter = $ this ->getPromiseTestAdapter ();
194
+ $ adapter ->resolve (42 );
195
+
196
+ $ fiber = new \Fiber (function () use ($ adapter ) {
197
+ $ adapter ->promise ()->then (function (int $ value ) {
198
+ \Fiber::suspend ($ value );
199
+ });
200
+ });
201
+
202
+ $ ret = $ fiber ->start ();
203
+ $ this ->assertEquals (42 , $ ret );
204
+
205
+ $ mock = $ this ->createCallableMock ();
206
+ $ mock
207
+ ->expects ($ this ->once ())
208
+ ->method ('__invoke ' )
209
+ ->with ($ this ->identicalTo (42 ));
210
+
211
+ $ adapter ->promise ()->then ($ mock );
212
+ }
213
+
187
214
/** @test */
188
215
public function cancelShouldReturnNullForFulfilledPromise ()
189
216
{
You can’t perform that action at this time.
0 commit comments