Skip to content

Commit 0580bd0

Browse files
authored
lib: use helper for readability
Used an extra `checkReusedHandle()` helper function to increase readability.
1 parent 533cafc commit 0580bd0

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

lib/internal/js_stream_socket.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,39 @@ 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(t) {
26+
let socket = t[owner_symbol];
2727

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

3235
return socket.isClosing();
3336
}
3437

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

4241
return socket.readStart();
4342
}
4443

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

5247
return socket.readStop();
5348
}
5449

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

6253
return socket.doShutdown(req);
6354
}
6455

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

7259
return socket.doWrite(req, bufs);
7360
}

0 commit comments

Comments
 (0)