net: return this from destroy()

PR-URL: https://github.com/nodejs/node/pull/13530
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Sam Roberts 2017-06-07 12:48:35 -07:00
parent 84f3b8f09f
commit cf24177aba
4 changed files with 10 additions and 3 deletions

View File

@ -643,6 +643,8 @@ callback.
added: v0.1.90
-->
* Returns: {net.Socket}
Ensures that no more I/O activity happens on this socket. Only necessary in
case of errors (parse error or so).

View File

@ -515,8 +515,10 @@ A Writable stream in object mode will always ignore the `encoding` argument.
added: v8.0.0
-->
* Returns: `this`
Destroy the stream, and emit the passed error. After this call, the
writible stream has ended. Implementors should not override this method,
writable stream has ended. Implementors should not override this method,
but instead implement [`writable._destroy`][writable-_destroy].
### Readable Streams

View File

@ -14,7 +14,7 @@ function destroy(err, cb) {
(!this._writableState || !this._writableState.errorEmitted)) {
process.nextTick(emitErrorNT, this, err);
}
return;
return this;
}
// we set destroyed to true before firing error callbacks in order
@ -39,6 +39,8 @@ function destroy(err, cb) {
cb(err);
}
});
return this;
}
function undestroy() {

View File

@ -10,7 +10,8 @@ server.listen(0, common.mustCall(function() {
const conn = net.createConnection(port);
conn.on('connect', common.mustCall(function() {
conn.destroy();
// Test destroy returns this, even on multiple calls when it short-circuits.
assert.strictEqual(conn, conn.destroy().destroy());
conn.on('error', common.mustCall(function(err) {
assert.strictEqual(err.message, 'This socket is closed');
}));