Created
June 13, 2021 17:43
-
-
Save wadez/080a3ee4d4d0f48b1631aba172f5b0ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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