-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS-400 Single entrypoint for worker and server #4893
Conversation
2330dad
to
7f6a405
Compare
90c229f
to
ff81757
Compare
Quality Gate passedIssues Measures |
I find the pattern strange, and more generally, I don't see why we need a different script for the server and the worker. I would have gone with this pattern: #!/usr/bin/env node
import { Worker, isMainThread, parentPort } from "node:worker_threads";
if (isMainThread) {
// this is the parent, aka the CLI script
const worker = new Worker(import.meta.filename);
worker.once("message", (message) => {
console.log('The worker did its thing', message);
});
worker.postMessage('Do something');
}
else {
// this is the worker
console.log('ParentPort is guaranteed to exist since we are not in the main thread');
parentPort.once("message", (message) => {
if (message === 'Do something') {
parentPort.postMessage("I did what I am supposed to do");
}
});
} There seems to be some partial implementation of this pattern - the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
||
/** | ||
* Handler to analyze in the same thread as HTTP server. Used for testing purposes | ||
* @param type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment @param type
helping?
case 'success': | ||
if (typeof message.result === 'object' && outputContainsAst(message.result)) { | ||
sendFormData(message.result, response); | ||
} else { | ||
response.send(message.result); | ||
} | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no curly braces around multiple statements? or is an if simple enough?
JS-400