Skip to content

Commit 35a1bd9

Browse files
sameer-coderMylesBorins
authored andcommitted
fs,net: emit 'ready' for fs streams and sockets
... in addition to the event names they currently use. Currently, various internal streams have different events that indicate that the underlying resource has successfully been established. This commit adds ready event for fs and net sockets to standardize on emitting ready for all of these streams. PR-URL: #19408Fixes: #19304 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 1f49de4 commit 35a1bd9

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

‎lib/fs.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ ReadStream.prototype.open = function(){
20042004

20052005
self.fd=fd;
20062006
self.emit('open',fd);
2007+
self.emit('ready');
20072008
// start the flow of data.
20082009
self.read();
20092010
});
@@ -2167,6 +2168,7 @@ WriteStream.prototype.open = function(){
21672168

21682169
this.fd=fd;
21692170
this.emit('open',fd);
2171+
this.emit('ready');
21702172
});
21712173
};
21722174

‎lib/net.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ function afterConnect(status, handle, req, readable, writable){
11751175
self._unrefTimer();
11761176

11771177
self.emit('connect');
1178+
self.emit('ready');
11781179

11791180
// start the first read, or get an immediate EOF.
11801181
// this doesn't actually consume any bytes, because len=0.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constfs=require('fs');
4+
constpath=require('path');
5+
consttmpdir=require('../common/tmpdir');
6+
7+
constreadStream=fs.createReadStream(__filename);
8+
readStream.on('ready',common.mustCall(()=>{},1));
9+
10+
constwriteFile=path.join(tmpdir.path,'write-fsreadyevent.txt');
11+
tmpdir.refresh();
12+
constwriteStream=fs.createWriteStream(writeFile,{autoClose: true});
13+
writeStream.on('ready',common.mustCall(()=>{},1));
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// This test ensures that socket.connect can be called without callback
5+
// which is optional.
6+
7+
constnet=require('net');
8+
9+
constserver=net.createServer(common.mustCall(function(conn){
10+
conn.end();
11+
server.close();
12+
})).listen(0,common.mustCall(function(){
13+
constclient=newnet.Socket();
14+
15+
client.on('ready',common.mustCall(function(){
16+
client.end();
17+
}));
18+
19+
client.connect(server.address());
20+
}));

0 commit comments

Comments
(0)