Skip to content
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

net: return this from destroy() #13530

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 3 additions & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +39,8 @@ function destroy(err, cb) {
cb(err);
}
});

return this;
}

function undestroy() {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-net-socket-destroy-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
Expand Down