File tree Expand file tree Collapse file tree 4 files changed +55
-2
lines changed Expand file tree Collapse file tree 4 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ public function promise()
23
23
$ this ->rejectCallback = $ reject ;
24
24
$ this ->notifyCallback = $ notify ;
25
25
}, $ this ->canceller );
26
+ $ this ->canceller = null ;
26
27
}
27
28
28
29
return $ this ->promise ;
Original file line number Diff line number Diff line change @@ -202,6 +202,8 @@ private function settle(ExtendedPromiseInterface $promise)
202
202
203
203
if ($ promise instanceof self) {
204
204
$ promise ->requiredCancelRequests ++;
205
+ } else {
206
+ $ this ->canceller = null ;
205
207
}
206
208
207
209
$ handlers = $ this ->handlers ;
Original file line number Diff line number Diff line change @@ -39,4 +39,41 @@ public function progressIsAnAliasForNotify()
39
39
40
40
$ deferred ->progress ($ sentinel );
41
41
}
42
+
43
+ /** @test */
44
+ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithException ()
45
+ {
46
+ gc_collect_cycles ();
47
+ $ deferred = new Deferred (function ($ resolve , $ reject ) {
48
+ $ reject (new \Exception ('foo ' ));
49
+ });
50
+ $ deferred ->promise ()->cancel ();
51
+ unset($ deferred );
52
+
53
+ $ this ->assertSame (0 , gc_collect_cycles ());
54
+ }
55
+
56
+ /** @test */
57
+ public function shouldRejectWithoutCreatingGarbageCyclesIfParentCancellerRejectsWithException ()
58
+ {
59
+ gc_collect_cycles ();
60
+ $ deferred = new Deferred (function ($ resolve , $ reject ) {
61
+ $ reject (new \Exception ('foo ' ));
62
+ });
63
+ $ deferred ->promise ()->then ()->cancel ();
64
+ unset($ deferred );
65
+
66
+ $ this ->assertSame (0 , gc_collect_cycles ());
67
+ }
68
+
69
+ /** @test */
70
+ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenceAndExplicitlyRejectWithException ()
71
+ {
72
+ gc_collect_cycles ();
73
+ $ deferred = new Deferred (function () use (&$ deferred ) { });
74
+ $ deferred ->reject (new \Exception ('foo ' ));
75
+ unset($ deferred );
76
+
77
+ $ this ->assertSame (0 , gc_collect_cycles ());
78
+ }
42
79
}
Original file line number Diff line number Diff line change @@ -138,7 +138,6 @@ public function shouldRejectWithoutCreatingGarbageCyclesIfResolverThrowsExceptio
138
138
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerWithReferenceThrowsException ()
139
139
{
140
140
gc_collect_cycles ();
141
-
142
141
$ promise = new Promise (function () {}, function () use (&$ promise ) {
143
142
throw new \Exception ('foo ' );
144
143
});
@@ -156,11 +155,25 @@ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerWithReference
156
155
public function shouldRejectWithoutCreatingGarbageCyclesIfResolverWithReferenceThrowsException ()
157
156
{
158
157
gc_collect_cycles ();
159
-
160
158
$ promise = new Promise (function () use (&$ promise ) {
161
159
throw new \Exception ('foo ' );
162
160
});
161
+ unset($ promise );
162
+
163
+ $ this ->assertSame (0 , gc_collect_cycles ());
164
+ }
163
165
166
+ /**
167
+ * @test
168
+ * @requires PHP 7
169
+ * @see self::shouldRejectWithoutCreatingGarbageCyclesIfCancellerWithReferenceThrowsException
170
+ */
171
+ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerHoldsReferenceAndResolverThrowsException ()
172
+ {
173
+ gc_collect_cycles ();
174
+ $ promise = new Promise (function () {
175
+ throw new \Exception ('foo ' );
176
+ }, function () use (&$ promise ) { });
164
177
unset($ promise );
165
178
166
179
$ this ->assertSame (0 , gc_collect_cycles ());
You can’t perform that action at this time.
0 commit comments