Skip to content

Commit

Permalink
lib: use helper for readability
Browse files Browse the repository at this point in the history
Used an extra `checkReusedHandle()` helper function to
increase readability.

PR-URL: #39649
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
VoltrexKeyva authored and danielleadams committed Aug 16, 2021
1 parent 338a166 commit 2751cdf
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions lib/internal/js_stream_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2751cdf

Please sign in to comment.