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

fs,net: emitting ready event for fs streams and network sockets in addition… #19408

Closed
wants to merge 5 commits into from
Closed
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 lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,7 @@ ReadStream.prototype.open = function() {

self.fd = fd;
self.emit('open', fd);
self.emit('ready');
// start the flow of data.
self.read();
});
Expand Down Expand Up @@ -2141,6 +2142,7 @@ WriteStream.prototype.open = function() {

this.fd = fd;
this.emit('open', fd);
this.emit('ready');
});
};

Expand Down
1 change: 1 addition & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ function afterConnect(status, handle, req, readable, writable) {
self._unrefTimer();

self.emit('connect');
self.emit('ready');

// start the first read, or get an immediate EOF.
// this doesn't actually consume any bytes, because len=0.
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-fs-ready-event-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');

const readStream = fs.createReadStream(__filename);
readStream.on('ready', common.mustCall(() => {}, 1));

const writeFile = path.join(tmpdir.path, 'write-fsreadyevent.txt');
tmpdir.refresh();
const writeStream = fs.createWriteStream(writeFile, { autoClose: true });
writeStream.on('ready', common.mustCall(() => {}, 1));
20 changes: 20 additions & 0 deletions test/parallel/test-net-socket-ready-without-cb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');

// This test ensures that socket.connect can be called without callback
// which is optional.

const net = require('net');

const server = net.createServer(common.mustCall(function(conn) {
conn.end();
server.close();
})).listen(0, common.mustCall(function() {
const client = new net.Socket();

client.on('ready', common.mustCall(function() {
client.end();
}));

client.connect(server.address());
}));