3.0.0 • Published 2 years ago

@nxtedition/shared v3.0.0

Weekly downloads
-
License
MIT License
Repository
github
Last release
2 years ago

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

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

2.0.15

2 years ago

2.0.3

2 years ago

2.0.16

2 years ago

2.0.2

2 years ago

2.0.13

2 years ago

2.0.5

2 years ago

2.0.14

2 years ago

2.0.4

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.12

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

3.0.0

2 years ago

2.0.17

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago