File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -263,10 +263,17 @@ private function invokeWaitList()
263
263
$ this ->waitList = null ;
264
264
265
265
foreach ($ waitList as $ result ) {
266
- $ result ->waitIfPending ();
267
- while ($ result ->result instanceof Promise) {
268
- $ result = $ result ->result ;
266
+ while (true ) {
269
267
$ result ->waitIfPending ();
268
+
269
+ if ($ result ->result instanceof Promise) {
270
+ $ result = $ result ->result ;
271
+ } else {
272
+ if ($ result ->result instanceof PromiseInterface) {
273
+ $ result ->result ->wait (false );
274
+ }
275
+ break ;
276
+ }
270
277
}
271
278
}
272
279
}
Original file line number Diff line number Diff line change 2
2
namespace GuzzleHttp \Promise \Tests ;
3
3
4
4
use GuzzleHttp \Promise \Coroutine ;
5
+ use GuzzleHttp \Promise \Promise ;
5
6
use GuzzleHttp \Promise \PromiseInterface ;
6
7
use PHPUnit_Framework_TestCase ;
7
8
use ReflectionClass ;
@@ -62,4 +63,43 @@ public function testShouldCancelResultPromiseAndOutsideCurrentPromise()
62
63
63
64
$ coroutine ->cancel ();
64
65
}
66
+
67
+ public function testWaitShouldResolveChainedCoroutines ()
68
+ {
69
+ $ promisor = function () {
70
+ return \GuzzleHttp \Promise \coroutine (function () {
71
+ yield $ promise = new Promise (function () use (&$ promise ) {
72
+ $ promise ->resolve (1 );
73
+ });
74
+ });
75
+ };
76
+
77
+ $ promise = $ promisor ()->then ($ promisor )->then ($ promisor );
78
+
79
+ $ this ->assertSame (1 , $ promise ->wait ());
80
+ }
81
+
82
+ public function testWaitShouldHandleIntermediateErrors ()
83
+ {
84
+ $ promise = \GuzzleHttp \Promise \coroutine (function () {
85
+ yield $ promise = new Promise (function () use (&$ promise ) {
86
+ $ promise ->resolve (1 );
87
+ });
88
+ })
89
+ ->then (function () {
90
+ return \GuzzleHttp \Promise \coroutine (function () {
91
+ yield $ promise = new Promise (function () use (&$ promise ) {
92
+ $ promise ->reject (new \Exception );
93
+ });
94
+ });
95
+ })
96
+ ->otherwise (function (\Exception $ error = null ) {
97
+ if (!$ error ) {
98
+ self ::fail ('Error did not propagate. ' );
99
+ }
100
+ return 3 ;
101
+ });
102
+
103
+ $ this ->assertSame (3 , $ promise ->wait ());
104
+ }
65
105
}
You can’t perform that action at this time.
0 commit comments