File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 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
2525
2626 public static function isCancelled (\Fiber $ fiber ): bool
2727 {
28- return self ::$ status [\spl_object_id ($ fiber )];
28+ return self ::$ status [\spl_object_id ($ fiber )] ?? false ;
2929 }
3030
3131 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
9797 }
9898 }
9999
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+
100121 /**
101122 * @dataProvider provideAwaiters
102123 */
@@ -230,6 +251,25 @@ public function testAwaitAsyncReturnsValueImmediatelyWhenPromiseIsFulfilled(call
230251 $ this ->assertEquals (1 , $ ticks );
231252 }
232253
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+
233273 /**
234274 * @dataProvider provideAwaiters
235275 */
You can’t perform that action at this time.
0 commit comments