Skip to content

Commit 937bbc5

Browse files
VoltrexKeyvajasnell
authored andcommitted
lib: use helper for readability
Used an extra `checkReusedHandle()` helper function to increase readability. PR-URL: #39649 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 1c7a19b commit 937bbc5

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

lib/internal/js_stream_socket.js

+13-24
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,41 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
2222
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
2323
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
2424

25-
function isClosing() {
26-
let socket = this[owner_symbol];
25+
function checkReusedHandle(self) {
26+
let socket = self[owner_symbol];
2727

28-
if (socket.constructor.name === 'ReusedHandle') {
28+
if (socket.constructor.name === 'ReusedHandle')
2929
socket = socket.handle;
30-
}
30+
31+
return socket;
32+
}
33+
34+
function isClosing() {
35+
const socket = checkReusedHandle(this);
3136

3237
return socket.isClosing();
3338
}
3439

3540
function onreadstart() {
36-
let socket = this[owner_symbol];
37-
38-
if (socket.constructor.name === 'ReusedHandle') {
39-
socket = socket.handle;
40-
}
41+
const socket = checkReusedHandle(this);
4142

4243
return socket.readStart();
4344
}
4445

4546
function onreadstop() {
46-
let socket = this[owner_symbol];
47-
48-
if (socket.constructor.name === 'ReusedHandle') {
49-
socket = socket.handle;
50-
}
47+
const socket = checkReusedHandle(this);
5148

5249
return socket.readStop();
5350
}
5451

5552
function onshutdown(req) {
56-
let socket = this[owner_symbol];
57-
58-
if (socket.constructor.name === 'ReusedHandle') {
59-
socket = socket.handle;
60-
}
53+
const socket = checkReusedHandle(this);
6154

6255
return socket.doShutdown(req);
6356
}
6457

6558
function onwrite(req, bufs) {
66-
let socket = this[owner_symbol];
67-
68-
if (socket.constructor.name === 'ReusedHandle') {
69-
socket = socket.handle;
70-
}
59+
const socket = checkReusedHandle(this);
7160

7261
return socket.doWrite(req, bufs);
7362
}

0 commit comments

Comments
 (0)