sync-rpc 1.3.0 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/index.test.js +19 -0
- package/lib/index.js +20 -15
- package/lib/worker.js +2 -2
- package/package.json +1 -1
|
@@ -22,3 +22,22 @@ rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
+
rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
|
|
26
|
+
let longMessage = '';
|
|
27
|
+
for (let i = 0; i < 100000; i++) {
|
|
28
|
+
longMessage += 'My Long Message Content';
|
|
29
|
+
}
|
|
30
|
+
test('profile large ' + fn.name, () => {
|
|
31
|
+
try {
|
|
32
|
+
rpc.configuration.fastestFunction = fn;
|
|
33
|
+
const start = Date.now();
|
|
34
|
+
for (let i = 0; i < 10; i++) {
|
|
35
|
+
expect(client(longMessage)).toBe(`sent ${longMessage} to My Server`);
|
|
36
|
+
}
|
|
37
|
+
const end = Date.now();
|
|
38
|
+
console.log('large ' + fn.name + ': ' + (end - start));
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
console.log('large ' + fn.name + ' fails');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -48,18 +48,18 @@ function findPort() {
|
|
|
48
48
|
const findPortResult = spawnSync(process.execPath, [
|
|
49
49
|
require.resolve('./find-port'),
|
|
50
50
|
]);
|
|
51
|
-
if (findPortResult.status !== 0) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
findPortResult.stderr.toString() ||
|
|
54
|
-
'find port exited with code ' + findPortResult.status
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
51
|
if (findPortResult.error) {
|
|
58
52
|
if (typeof findPortResult.error === 'string') {
|
|
59
53
|
throw new Error(findPortResult.error);
|
|
60
54
|
}
|
|
61
55
|
throw findPortResult.error;
|
|
62
56
|
}
|
|
57
|
+
if (findPortResult.status !== 0) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
findPortResult.stderr.toString() ||
|
|
60
|
+
'find port exited with code ' + findPortResult.status
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
63
|
const portString = findPortResult.stdout.toString('utf8').trim();
|
|
64
64
|
if (!/^[0-9]+$/.test(portString)) {
|
|
65
65
|
throw new Error('Invalid port number string returned: ' + portString);
|
|
@@ -91,7 +91,12 @@ function nativeNC(port, input) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
function nodeNC(port, input) {
|
|
94
|
-
|
|
94
|
+
const src = nodeNetCatSrc(port, input);
|
|
95
|
+
if (src.length < 1000) {
|
|
96
|
+
return spawnSync(process.execPath, ['-e', src]);
|
|
97
|
+
} else {
|
|
98
|
+
return spawnSync(process.execPath, [], {input: src});
|
|
99
|
+
}
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
function test(fn, port) {
|
|
@@ -117,25 +122,25 @@ function sendMessage(input) {
|
|
|
117
122
|
try {
|
|
118
123
|
return JSON.parse(res.stdout.toString('utf8'));
|
|
119
124
|
} catch (ex) {
|
|
125
|
+
if (res.error) {
|
|
126
|
+
if (typeof res.error === 'string') res.error = new Error(res.error);
|
|
127
|
+
throw res.error;
|
|
128
|
+
}
|
|
120
129
|
if (res.status !== 0) {
|
|
121
130
|
throw new Error(
|
|
122
131
|
configuration.fastestFunction.name +
|
|
123
132
|
' failed:\n' +
|
|
124
|
-
res.stdout.toString() +
|
|
133
|
+
(res.stdout && res.stdout.toString()) +
|
|
125
134
|
'\n' +
|
|
126
|
-
res.stderr.toString()
|
|
135
|
+
(res.stderr && res.stderr.toString())
|
|
127
136
|
);
|
|
128
137
|
}
|
|
129
|
-
if (res.error) {
|
|
130
|
-
if (typeof res.error === 'string') res.error = new Error(res.error);
|
|
131
|
-
throw res.error;
|
|
132
|
-
}
|
|
133
138
|
throw new Error(
|
|
134
139
|
configuration.fastestFunction.name +
|
|
135
140
|
' failed:\n' +
|
|
136
|
-
res.stdout.toString() +
|
|
141
|
+
(res.stdout && res.stdout).toString() +
|
|
137
142
|
'\n' +
|
|
138
|
-
res.stderr.toString()
|
|
143
|
+
(res.stderr && res.stderr).toString()
|
|
139
144
|
);
|
|
140
145
|
}
|
|
141
146
|
}
|
package/lib/worker.js
CHANGED
|
@@ -9,10 +9,10 @@ const modules = [];
|
|
|
9
9
|
|
|
10
10
|
const NULL_PROMISE = Promise.resolve(null);
|
|
11
11
|
const server = net.createServer({allowHalfOpen: true}, c => {
|
|
12
|
-
let
|
|
12
|
+
let responded = false;
|
|
13
13
|
function respond(data) {
|
|
14
14
|
if (responded) return;
|
|
15
|
-
|
|
15
|
+
responded = true;
|
|
16
16
|
c.end(JSON.stringify(data));
|
|
17
17
|
}
|
|
18
18
|
|