lib: use helper for readability

Used an extra `checkReusedHandle()` helper function to
increase readability.

PR-URL: https://github.com/nodejs/node/pull/39649
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Voltrex
2021-08-03 17:44:10 +04:30
committed by James M Snell
parent 1c7a19b22b
commit 937bbc5571

View File

@@ -22,52 +22,41 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
function isClosing() {
let socket = this[owner_symbol];
function checkReusedHandle(self) {
let socket = self[owner_symbol];
if (socket.constructor.name === 'ReusedHandle') {
if (socket.constructor.name === 'ReusedHandle')
socket = socket.handle;
}
return socket;
}
function isClosing() {
const socket = checkReusedHandle(this);
return socket.isClosing();
}
function onreadstart() {
let socket = this[owner_symbol];
if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
const socket = checkReusedHandle(this);
return socket.readStart();
}
function onreadstop() {
let socket = this[owner_symbol];
if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
const socket = checkReusedHandle(this);
return socket.readStop();
}
function onshutdown(req) {
let socket = this[owner_symbol];
if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
const socket = checkReusedHandle(this);
return socket.doShutdown(req);
}
function onwrite(req, bufs) {
let socket = this[owner_symbol];
if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
const socket = checkReusedHandle(this);
return socket.doWrite(req, bufs);
}