Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created March 17, 2019 00:34
Show Gist options
  • Save JeffML/b6b8dc945c60fd56da507f8bcb742a19 to your computer and use it in GitHub Desktop.
Save JeffML/b6b8dc945c60fd56da507f8bcb742a19 to your computer and use it in GitHub Desktop.
const { workerData, parentPort, isMainThread } = require("worker_threads");
// You can do any heavy stuff here, in a synchronous way
// without blocking the "main thread"
parentPort.on("message", message => {
if (message === "exit") {
parentPort.postMessage("sold!");
parentPort.close();
} else {
parentPort.postMessage({ going: message });
}
});
parentPort.postMessage({ start: workerData, isMainThread });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment