Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created June 22, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deleteman/df2119b1d386d3de3f2d86bad12ff32e to your computer and use it in GitHub Desktop.
Save deleteman/df2119b1d386d3de3f2d86bad12ff32e to your computer and use it in GitHub Desktop.
const { parentPort } = require('worker_threads');
function random(min, max) {
return Math.random() * (max - min) + min
}
const sorter = require("./test2-worker");
const start = Date.now()
let bigList = Array(1000000).fill().map( (_) => random(1,10000))
/**
//you can receive messages from the main thread this way:
parentPort.on('message', (msg) => {
console.log("Main thread finished on: ", (msg.timeDiff / 1000), " seconds...");
})
*/
sorter.sort(bigList);
parentPort.postMessage({ val: sorter.firstValue, timeDiff: Date.now() - start});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment