🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@nxtedition/shared

Package Overview
Dependencies
Maintainers
2
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nxtedition/shared

Ring Buffer for NodeJS cross Worker communication

npmnpm
Version
0.0.1
Version published
Weekly downloads
2.5K
71.55%
Maintainers
2
Weekly downloads
 
Created
Source

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)

shared.reader(writer, async (buffer) => {
  console.log(`From worker ${buffer}`)
  await tp.setTimeout(1e3) // Backpressure
})

while (true) {
  await writeToParent(Buffer.from('Hello from parent')
}
// worker.js

import * as shared from '@nxtedition/shared'
import tp from 'timers/promise'

const writeToParent = shared.writer(workerData.writer)

shared.reader(workerData.reader, (buffer) => {
  console.log(`From parent ${buffer}`)
  await tp.setTimeout(1e3) // Backpressure
})

while (true) {
  await writeToParent(Buffer.from('Hello from worker')
}

FAQs

Package last updated on 08 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts