-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: promise version of streams.finished
call cleanup after eos
#44862
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening a PR! Can you please add a unit test?
i added the following tests
In addition, I want to make sure that the cleanup function has been called as expected I didn't find any example of how to detect listeners has been properly removed I see it hasn't been tested here as well : https://github.com/nodejs/node/blob/main/test/parallel/test-stream-end-of-streams.js Can you please help me think of a simple way to check |
Thank you anyway, I was able to find a simple solution
|
streams.finished
call clean upstreams.finished
call clean up
1ba59b1
to
669dc00
Compare
implement autoCleanup logic. update docs add autoCleanup description ref: nodejs#44556
doc: update autoCleanup default value to false
streams.finished
call clean upstreams.finished
call cleanup after eos
Hey I was looking though good first issues for hacktoberfest and I saw #44556. After looking at this pull request, I wondered whether or not the function finished(stream, opts) {
...
return new Promise((resolve, reject) => {
let result;
const cleanup = eos(stream, opts, (err) => {
if (err) {
result = err;
}
});
if (autoCleanup) {
cleanup();
}
if (result) {
reject(result);
} else {
resolve();
}
});
} I made the following changes to the tests. diff --git a/test/parallel/test-stream-promises.js b/test/parallel/test-stream-promises.js
index fae2c37492..ae98804776 100644
--- a/test/parallel/test-stream-promises.js
+++ b/test/parallel/test-stream-promises.js
@@ -120,7 +120,7 @@ assert.strictEqual(finished, promisify(stream.finished));
const streamObj = new Writable();
assert.strictEqual(streamObj.listenerCount('end'), 0);
finished(streamObj, { cleanup: false }).then(() => {
- assert.strictEqual(streamObj.listenerCount('end'), 1);
+ assert.strictEqual(streamObj.listenerCount('end'), "FOO");
});
}
@@ -130,7 +130,7 @@ assert.strictEqual(finished, promisify(stream.finished));
const streamObj = new Writable();
assert.strictEqual(streamObj.listenerCount('end'), 0);
finished(streamObj, { cleanup: true }).then(() => {
- assert.strictEqual(streamObj.listenerCount('end'), 0);
+ assert.strictEqual(streamObj.listenerCount('end'), "FOO");
});
} Even with these changes, the tests still passed. > ./tools/test.py test/parallel/test-stream-promises.js
[00:00|% 100|+ 1|- 0]: Done Are we certain the |
{ | ||
const streamObj = new Writable(); | ||
assert.strictEqual(streamObj.listenerCount('end'), 0); | ||
finished(streamObj, { cleanup: true }).then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpic: wrap with common.mustCall
{ | ||
const streamObj = new Writable(); | ||
assert.strictEqual(streamObj.listenerCount('end'), 0); | ||
finished(streamObj).then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Landed in 84064bf |
ref: #44556
src: add autoCleanup logic to finished
docs: add autoCleanup true as default