3.0.0 • Published 3 years ago
@nxtedition/shared v3.0.0
shared
Ring Buffer for NodeJS cross Worker communication.
Install
npm i @nxtedition/shared
Quick Start
// index.js
import * as shared from '@nxtedition/shared'
import tp from 'timers/promise'
const writer = shared.alloc(16 * 1024 * 1024)
const reader = shared.alloc(16 * 1024 * 1024)
const worker = new Worker(new URL('worker.js', import.meta.url), {
workerData: { reader, writer },
})
const writeToWorker = shared.writer(reader)
writeToWorker(Buffer.from('ping'))
for await (const buffer of shared.reader(writer)) {
console.log(`From worker ${buffer}`)
await tp.setTimeout(1e3) // Backpressure
writeToWorker(Buffer.from('pong'))
}
// worker.js
import * as shared from '@nxtedition/shared'
import tp from 'timers/promise'
const writeToParent = shared.writer(workerData.writer)
for await (const buffer of shared.reader(workerData.reader)) {
console.log(`From parent ${buffer}`)
await tp.setTimeout(1e3) // Backpressure
writeToWorker(Buffer.from('pong'))
}
1.2.0
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.4.2
3 years ago
1.4.1
3 years ago
1.4.0
3 years ago
1.3.0
3 years ago
1.2.1
3 years ago
1.1.2
3 years ago
2.0.15
3 years ago
2.0.3
3 years ago
2.0.16
3 years ago
2.0.2
3 years ago
2.0.13
3 years ago
2.0.5
3 years ago
2.0.14
3 years ago
2.0.4
3 years ago
2.0.11
3 years ago
2.0.7
3 years ago
2.0.12
3 years ago
2.0.6
3 years ago
2.0.9
3 years ago
2.0.10
3 years ago
2.0.8
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
3.0.0
3 years ago
2.0.17
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago