mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/pull/19408 Fixes: https://github.com/nodejs/node/issues/19304 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
1f49de4b24
commit
35a1bd97ba
4 files changed
+36
No files matched your search
@@ -2004,6 +2004,7 @@ ReadStream.prototype.open = function() {
|
||||
|
||||
self.fd = fd;
|
||||
self.emit('open', fd);
|
||||
self.emit('ready');
|
||||
// start the flow of data.
|
||||
self.read();
|
||||
});
|
||||
@@ -2167,6 +2168,7 @@ WriteStream.prototype.open = function() {
|
||||
|
||||
this.fd = fd;
|
||||
this.emit('open', fd);
|
||||
this.emit('ready');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1175,6 +1175,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.
|
||||
|
||||
@@ -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));
|
||||
@@ -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());
|
||||
}));
|
||||
Reference in new issue
Block a user