1.0.11 • Published 2 years ago

@anzerr/thread.node v1.0.11

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

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());
1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.1

5 years ago

1.0.2

5 years ago