Skip to content

Instantly share code, notes, and snippets.

@chnbohwr
Created June 25, 2018 09:14
Show Gist options
  • Save chnbohwr/8622f4e2a7235391aef954920ab521ed to your computer and use it in GitHub Desktop.
Save chnbohwr/8622f4e2a7235391aef954920ab521ed to your computer and use it in GitHub Desktop.
const { Worker } = require('worker_threads');
const path = require('path');
const buffer = new SharedArrayBuffer(1);
const worker = new Worker(path.resolve('./worker.js'));
worker.on('message', () => {
// check buffer was changed ?
const int8Array = new Int8Array(buffer);
console.log(`main thread buffer: ${int8Array[0]}`)
});
worker.postMessage(buffer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment