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.
  • Loading branch information
VoltrexKeyva committed Aug 3, 2021
1 parent 533cafc commit 0580bd0
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions lib/internal/js_stream_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,39 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');

function isClosing() {
let socket = this[owner_symbol];
function checkReusedHandle(t) {
let socket = t[owner_symbol];

if (socket.constructor.name === 'ReusedHandle') {
if (socket.constructor.name === 'ReusedHandle')
socket = socket.handle;
}
}

function isClosing() {
checkReusedHandle(this);

return socket.isClosing();
}

function onreadstart() {
let socket = this[owner_symbol];

if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
checkReusedHandle(this);

return socket.readStart();
}

function onreadstop() {
let socket = this[owner_symbol];

if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
checkReusedHandle(this);

return socket.readStop();
}

function onshutdown(req) {
let socket = this[owner_symbol];

if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
checkReusedHandle(this);

return socket.doShutdown(req);
}

function onwrite(req, bufs) {
let socket = this[owner_symbol];

if (socket.constructor.name === 'ReusedHandle') {
socket = socket.handle;
}
checkReusedHandle(this);

return socket.doWrite(req, bufs);
}
Expand Down

0 comments on commit 0580bd0

Please sign in to comment.