Created
March 17, 2019 00:34
-
-
Save JeffML/b6b8dc945c60fd56da507f8bcb742a19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { 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