-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportTest.js
51 lines (43 loc) · 1.07 KB
/
portTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const port = require('port');
function createPort(readPort, writePort, resultArg, callback) {
return new port({
'read': readPort,
'write': writePort,
'flags': {
'noprefs': true,
'stderr': true,
'open': `patch.pd`
}
}).on('stderr', (buffer) => {
const data = buffer.toString();
const result = data.match(new RegExp(`^${resultArg}:\s(.+)`));
if (result) {
callback(result[1]);
}
}).create();
}
function myCallback(data) {
const list = data.split(',').map(Number);
const multipliedList = list.map(num => num * 3);
return multipliedList;
}
createPort(1111, 1112, 'result', myCallback);
const pd = new port({
'read': 1111, // [netsend]
'write': 1112, // [netreceive]
'flags': {
'noprefs': true,
'stderr': true,
'open': `patch.pd`
}
}).on('stderr', (buffer) => {
const data = buffer.toString();
const result = data.match(/^result:\s(.+)/);
console.log(result[1])
// if (result) {
// const list = result[1].split(',').map(Number);
// const multipliedList = list.map(num => num * 3);
// console.log(multipliedList);
// }
})
.create();