3.0.0 • Published 4 years ago
@nxtedition/shared v3.0.0
shared
Ring Buffer for NodeJS cross Worker communication.
Install
npm i @nxtedition/sharedQuick 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
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.4.2
4 years ago
1.4.1
4 years ago
1.4.0
4 years ago
1.3.0
4 years ago
1.2.1
4 years ago
1.1.2
4 years ago
2.0.15
4 years ago
2.0.3
4 years ago
2.0.16
4 years ago
2.0.2
4 years ago
2.0.13
4 years ago
2.0.5
4 years ago
2.0.14
4 years ago
2.0.4
4 years ago
2.0.11
4 years ago
2.0.7
4 years ago
2.0.12
4 years ago
2.0.6
4 years ago
2.0.9
4 years ago
2.0.10
4 years ago
2.0.8
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
3.0.0
4 years ago
2.0.17
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago