Socket
Socket
Sign inDemoInstall

@anzerr/thread.node

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @anzerr/thread.node

Test to understand how the new 'worker_threads' works with SharedArrayBuffer.


Version published
Weekly downloads
123
increased by20.59%
Maintainers
1
Install size
8.93 kB
Created
Weekly downloads
 

Readme

Source

Intro

Test to understand how the new 'worker_threads' works with SharedArrayBuffer.

Install
npm install --save git+https://github.com/anzerr/worker_threads.node.git
npm install --save @anzerr/thread.node

Example

const {Executors} = require('@anzerr/thread.node');

let pool = Executors.singleThreadPool();

const buffer = new SharedArrayBuffer(16);

pool.submit(async (d) => {
	new Int32Array(d)[0] = 42;
	return {'cat': 10};
}, buffer).then((res) => {
	console.log('sumbit1', res);
	return Promise.all([
		pool.submit(async (d) => {
			const b = Buffer.from(d);
			const path = require('path');
			b.write(path.resolve(process.cwd()));
		}, buffer).then((result) => console.log('1', result)),
		pool.submit(async (d) => {
			return Buffer.from(d)[0];
		}, buffer).then((result) => console.log('2', result)),
		pool.submit(async (d) => {
			return d.data.toString();
		}, {data: 'egg'}).then((result) => console.log('3', result))
	]);
}).then(() => {
	return pool.close();
}).catch((e) => {
	console.log(e);
	return pool.close();
}).then(() => {
	console.log('done', Buffer.from(buffer).toString());

FAQs

Last updated on 17 Feb 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc