-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
33 lines (28 loc) · 853 Bytes
/
index.mjs
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
import { alloc, reader } from './shared.mjs'
import { Worker } from 'node:worker_threads'
import path from 'node:path'
import { setTimeout } from 'node:timers/promises'
const __dirname = path.dirname(new URL(import.meta.url).pathname)
setInterval(() => {
console.log("#")
}, 1e3)
const numValues = 1000
const size = 39
const minWrite = 4
const maxWrite = size - 8
const shared = alloc(size)
const workerPath = path.join(__dirname, 'write-async-worker.mjs')
const worker = new Worker(workerPath, { workerData: { shared, numValues, minWrite, maxWrite } })
await new Promise((resolve) => {
let expected = 0
reader(shared, async (data) => {
const value = data.readInt32LE(0)
if (value !== expected) {
throw new Error(`wrong value actual=${value} expected=${expected}`)
}
expected++
if (expected === numValues) {
resolve()
}
})
})