Skip to content

Commit 063c4fa

Browse files
sam-githubMylesBorins
authored andcommitted
lib: return this from net.Socket.end()
PR-URL: #13481 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 43a2bc0 commit 063c4fa

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

doc/api/net.md

+2
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ server will still send some data.
575575
If `data` is specified, it is equivalent to calling
576576
`socket.write(data, encoding)` followed by `socket.end()`.
577577

578+
Returns `socket`.
579+
578580
### socket.localAddress
579581
<!-- YAML
580582
added: v0.9.6

lib/net.js

+2
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ Socket.prototype.end = function(data, encoding) {
444444
this.read(0);
445445
else
446446
maybeDestroy(this);
447+
448+
return this;
447449
};
448450

449451

test/parallel/test-socket-write-after-fin.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const net = require('net');
5-
const expected = 'hello1hello2hello3\nTHUNDERMUSCLE!';
5+
const expected = 'hello1hello2hello3\nbye';
66

77
const server = net.createServer({
88
allowHalfOpen: true
@@ -35,5 +35,6 @@ server.listen(0, common.mustCall(function() {
3535
sock.write('hello1');
3636
sock.write('hello2');
3737
sock.write('hello3\n');
38-
sock.end('THUNDERMUSCLE!');
38+
assert.strictEqual(sock.end('bye'), sock);
39+
3940
}));

0 commit comments

Comments
 (0)