-
Notifications
You must be signed in to change notification settings - Fork 0
/
child.ts
39 lines (35 loc) · 970 Bytes
/
child.ts
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
import { equal } from 'assert'
import { init, setString, getString, getBuffer } from './index'
const memId = "string.link"
const bufferMemId = "buffer.link"
function generateBigString() {
let bigStr = '';
for (let i = 0; i < 50; i++) {
bigStr += 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ';
}
return bigStr;
}
function generateBigBuffer() {
return Buffer.from(generateBigString())
}
process.on('message', (msg: { type: string, data: any }) => {
if (msg.type === 'share') {
const data = getString(memId)
if (!process.env.BENCH) {
equal(data, generateBigString())
process.send?.({
type: 'exit'
})
}
} else if (msg.type === 'shareBuffer') {
const data = getBuffer(bufferMemId)
if (!process.env.BENCH) {
equal(data.toString(), generateBigBuffer().toString())
process.send?.({
type: 'exit'
})
}
} else if (msg.type === 'ipc') {
const str = msg.data
}
})