Skip to content

Commit 69f806c

Browse files
sam-githubaddaleax
authored andcommitted
net: return this from destroy()
PR-URL: #13530 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e2d3254 commit 69f806c

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

doc/api/net.md

+2
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ callback.
643643
added: v0.1.90
644644
-->
645645

646+
* Returns: {net.Socket}
647+
646648
Ensures that no more I/O activity happens on this socket. Only necessary in
647649
case of errors (parse error or so).
648650

doc/api/stream.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ A Writable stream in object mode will always ignore the `encoding` argument.
515515
added: v8.0.0
516516
-->
517517

518+
* Returns: `this`
519+
518520
Destroy the stream, and emit the passed error. After this call, the
519-
writible stream has ended. Implementors should not override this method,
521+
writable stream has ended. Implementors should not override this method,
520522
but instead implement [`writable._destroy`][writable-_destroy].
521523

522524
### Readable Streams

lib/internal/streams/destroy.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function destroy(err, cb) {
1414
(!this._writableState || !this._writableState.errorEmitted)) {
1515
process.nextTick(emitErrorNT, this, err);
1616
}
17-
return;
17+
return this;
1818
}
1919

2020
// we set destroyed to true before firing error callbacks in order
@@ -39,6 +39,8 @@ function destroy(err, cb) {
3939
cb(err);
4040
}
4141
});
42+
43+
return this;
4244
}
4345

4446
function undestroy() {

test/parallel/test-net-socket-destroy-send.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ server.listen(0, common.mustCall(function() {
1010
const conn = net.createConnection(port);
1111

1212
conn.on('connect', common.mustCall(function() {
13-
conn.destroy();
13+
// Test destroy returns this, even on multiple calls when it short-circuits.
14+
assert.strictEqual(conn, conn.destroy().destroy());
1415
conn.on('error', common.mustCall(function(err) {
1516
assert.strictEqual(err.message, 'This socket is closed');
1617
}));

0 commit comments

Comments
 (0)