File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,6 @@ public function __construct(PromiseInterface $promise)
30
30
31
31
// TODO: support backpressure
32
32
33
- // try to cancel promise once the stream closes
34
- if ($ promise instanceof CancellablePromiseInterface) {
35
- $ out ->on ('close ' , function () use ($ promise ) {
36
- $ promise ->cancel ();
37
- });
38
- }
39
-
40
33
$ this ->promise = $ promise ->then (
41
34
function ($ stream ) {
42
35
if (!($ stream instanceof ReadableStreamInterface)) {
@@ -106,6 +99,11 @@ public function close()
106
99
107
100
$ this ->closed = true ;
108
101
102
+ // try to cancel promise once the stream closes
103
+ if ($ this ->promise instanceof CancellablePromiseInterface) {
104
+ $ this ->promise ->cancel ();
105
+ }
106
+
109
107
$ this ->emit ('end ' , array ($ this ));
110
108
$ this ->emit ('close ' , array ($ this ));
111
109
}
Original file line number Diff line number Diff line change @@ -153,4 +153,15 @@ public function testEmitsEndAndClosesWhenInputEmitsEnd()
153
153
154
154
$ this ->assertFalse ($ stream ->isReadable ());
155
155
}
156
+
157
+ public function testEmitsCloseOnlyOnceWhenClosingStreamMultipleTimes ()
158
+ {
159
+ $ promise = new Promise \Promise (function () { });
160
+ $ stream = Stream \unwrapReadable ($ promise );
161
+
162
+ $ stream ->on ('close ' , $ this ->expectCallableOnce ());
163
+
164
+ $ stream ->close ();
165
+ $ stream ->close ();
166
+ }
156
167
}
You can’t perform that action at this time.
0 commit comments