File tree 2 files changed +41
-1
lines changed 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public static function cancel(\Fiber $fiber): void
25
25
26
26
public static function isCancelled (\Fiber $ fiber ): bool
27
27
{
28
- return self ::$ status [\spl_object_id ($ fiber )];
28
+ return self ::$ status [\spl_object_id ($ fiber )] ?? false ;
29
29
}
30
30
31
31
public static function setPromise (\Fiber $ fiber , PromiseInterface $ promise ): void
Original file line number Diff line number Diff line change @@ -97,6 +97,27 @@ public function testAwaitAsyncThrowsExceptionImmediatelyWhenPromiseIsRejected(ca
97
97
}
98
98
}
99
99
100
+ /**
101
+ * @dataProvider provideAwaiters
102
+ */
103
+ public function testAwaitThrowsExceptionImmediatelyInCustomFiberWhenPromiseIsRejected (callable $ await )
104
+ {
105
+ $ fiber = new \Fiber (function () use ($ await ) {
106
+ $ promise = new Promise (function ($ resolve ) {
107
+ throw new \RuntimeException ('Test ' );
108
+ });
109
+
110
+ return $ await ($ promise );
111
+ });
112
+
113
+ try {
114
+ $ fiber ->start ();
115
+ } catch (\RuntimeException $ e ) {
116
+ $ this ->assertTrue ($ fiber ->isTerminated ());
117
+ $ this ->assertEquals ('Test ' , $ e ->getMessage ());
118
+ }
119
+ }
120
+
100
121
/**
101
122
* @dataProvider provideAwaiters
102
123
*/
@@ -230,6 +251,25 @@ public function testAwaitAsyncReturnsValueImmediatelyWhenPromiseIsFulfilled(call
230
251
$ this ->assertEquals (1 , $ ticks );
231
252
}
232
253
254
+ /**
255
+ * @dataProvider provideAwaiters
256
+ */
257
+ public function testAwaitReturnsValueImmediatelyInCustomFiberWhenPromiseIsFulfilled (callable $ await )
258
+ {
259
+ $ fiber = new \Fiber (function () use ($ await ) {
260
+ $ promise = new Promise (function ($ resolve ) {
261
+ $ resolve (42 );
262
+ });
263
+
264
+ return $ await ($ promise );
265
+ });
266
+
267
+ $ fiber ->start ();
268
+
269
+ $ this ->assertTrue ($ fiber ->isTerminated ());
270
+ $ this ->assertEquals (42 , $ fiber ->getReturn ());
271
+ }
272
+
233
273
/**
234
274
* @dataProvider provideAwaiters
235
275
*/
You can’t perform that action at this time.
0 commit comments