Skip to content

Instantly share code, notes, and snippets.

@wadez
Created June 13, 2021 17:43
Show Gist options
  • Save wadez/080a3ee4d4d0f48b1631aba172f5b0ad to your computer and use it in GitHub Desktop.
Save wadez/080a3ee4d4d0f48b1631aba172f5b0ad to your computer and use it in GitHub Desktop.
const {parentPort, workerData} = require("worker_threads");
var start = new Date();
const interval = setInterval(() => {
var number = Math.random()
var end = new Date();
var diff = (end - start) / 1000
var secs = Math.floor(diff * 100) / 100
if (number > 0.9) {
parentPort.postMessage(`found ${number} after ${secs} seconds`)
clearInterval(interval) // important! otherwise zombie
// parentPort.close(); // optional
}
}, 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment