Skip to content

Commit 45bc784

Browse files
committed
lint: fix style issues in duplexpair and its tests
1 parent f7d7d13 commit 45bc784

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

lib/internal/streams/duplexpair.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,13 @@ class DuplexSide extends Duplex {
5353

5454

5555
_destroy(err, callback) {
56-
5756
if (err) {
5857
// Error case: tell the other side to also destroy with that error.
5958
this.#otherSide.destroy(err);
60-
} else {
59+
} else if (this.#otherSide && !this.#otherSide.destroyed) {
6160
// Graceful close case (destroy() without error):
6261
// send an EOF to the other side's readable end if it hasn't already closed.
63-
if (this.#otherSide && !this.#otherSide.destroyed) {
64-
this.#otherSide.push(null);
65-
}
62+
this.#otherSide.push(null);
6663
}
6764
callback(err);
6865
}

test/parallel/test-duplex-error.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const common = require('../common');
34
const assert = require('assert');
45
const { duplexPair } = require('stream');
56

@@ -8,32 +9,22 @@ const [sideA, sideB] = duplexPair();
89
let sideAErrorReceived = false;
910
let sideBErrorReceived = false;
1011

11-
// Add error handlers
12-
sideA.on('error', (err) => {
12+
// Use common.mustCall inside the listeners to ensure they trigger
13+
sideA.on('error', common.mustCall((err) => {
1314
sideAErrorReceived = true;
14-
});
15-
sideB.on('error', (err) => {
15+
}));
16+
17+
sideB.on('error', common.mustCall((err) => {
1618
sideBErrorReceived = true;
17-
});
19+
}));
1820

19-
// Ensure the streams are flowing
2021
sideA.resume();
2122
sideB.resume();
2223

23-
// Destroy sideB with an error
2424
sideB.destroy(new Error('Simulated error'));
2525

26-
// Wait for event loop to process error events
27-
setImmediate(() => {
28-
assert.strictEqual(
29-
sideAErrorReceived,
30-
true,
31-
'sideA should receive the error when sideB is destroyed with an error'
32-
);
33-
assert.strictEqual(
34-
sideBErrorReceived,
35-
true,
36-
'sideB should emit its own error when destroyed'
37-
);
38-
});
39-
26+
// Wrap the callback in common.mustCall()
27+
setImmediate(common.mustCall(() => {
28+
assert.strictEqual(sideAErrorReceived, true);
29+
assert.strictEqual(sideBErrorReceived, true);
30+
}));

0 commit comments

Comments
 (0)