-
-
Save navanathjadhav/65143c47884956eab5b63d5b073aa69e to your computer and use it in GitHub Desktop.
index.js, main thread file
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
/* | |
* index.js, main thread file | |
*/ | |
const { Worker } = require("worker_threads"); | |
function runService(workerData) { | |
return new Promise((resolve, reject) => { | |
const worker = new Worker("./worker.js", { workerData }); | |
worker.on("message", resolve); | |
worker.on("error", reject); | |
worker.on("exit", (code) => { | |
if (code !== 0) | |
reject( | |
new Error(`Stopped the Worker Thread with the exit code: ${code}`) | |
); | |
}); | |
}); | |
} | |
async function run() { | |
const result = await runService("Ever Blogs"); | |
console.log(result); | |
} | |
run().catch((err) => console.error(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment