-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
Allow manipulating the generator in Duplex.from() #55096
base: main
Are you sure you want to change the base?
Conversation
094e571
to
c22a808
Compare
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.
lgtm with a few nits, good job
lib/internal/streams/duplexify.js
Outdated
return end(err).then(originalThrow.bind(this, err)); | ||
}; | ||
|
||
|
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.
please remove this empty line
lib/internal/streams/duplexify.js
Outdated
|
||
// Not using try/finally because asyncGenerator.return() should work even | ||
// if the generator was never started. | ||
|
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.
Could you attach this comment to the section it refers to?
} | ||
|
||
{ | ||
const r = Readable.from(['foo', 'bar', 'bar']); |
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.
const r = Readable.from(['foo', 'bar', 'bar']); | |
const r = Readable.from(['foo', 'bar', 'baz']); |
(for consistency)
const r = Readable.from(['foo', 'bar', 'bar']); | ||
pipeline( | ||
r, | ||
Duplex.from(async function(asyncGenerator) { | ||
const values = await Array.fromAsync(asyncGenerator); | ||
assert.deepStrictEqual(values, ['foo', 'bar', 'bar']); |
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.
const r = Readable.from(['foo', 'bar', 'bar']); | |
pipeline( | |
r, | |
Duplex.from(async function(asyncGenerator) { | |
const values = await Array.fromAsync(asyncGenerator); | |
assert.deepStrictEqual(values, ['foo', 'bar', 'bar']); | |
const r = Readable.from(['foo', 'bar', 'baz']); | |
pipeline( | |
r, | |
Duplex.from(async function(asyncGenerator) { | |
const values = await Array.fromAsync(asyncGenerator); | |
assert.deepStrictEqual(values, ['foo', 'bar', 'baz']); |
(for consistency)
lib/internal/streams/duplexify.js
Outdated
let d; | ||
|
||
const { value, write, final, destroy } = fromAsyncGen(body, () => { | ||
if (d) destroyer(d); |
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.
if (d) destroyer(d); | |
destroyer(d); |
The destroyer
function already checks whether the stream exists:
node/lib/internal/streams/destroy.js
Line 323 in 3c5ceff
if (!stream || isDestroyed(stream)) { |
lib/internal/streams/duplexify.js
Outdated
const promise = FunctionPrototypeCall( | ||
then, | ||
value, | ||
(val) => { | ||
destroyer(d, null); |
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.
destroyer(d, null); | |
destroyer(d); |
If err
is null
, it's treated the same as if it's undefined:
node/lib/internal/streams/destroy.js
Line 327 in 3c5ceff
if (!err && !isFinished(stream)) { |
c77637d
to
b2d5432
Compare
Not sure what is wrong with the tests that are not passing:
|
b2ef820
to
881baa0
Compare
881baa0
to
12439c6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #55096 +/- ##
==========================================
- Coverage 88.24% 88.24% -0.01%
==========================================
Files 651 651
Lines 183877 183925 +48
Branches 35858 35866 +8
==========================================
+ Hits 162266 162307 +41
+ Misses 14901 14899 -2
- Partials 6710 6719 +9
|
Fix for #55077