Skip to content
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

Add individual import to multithreading #245

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions static/scripts/threadBlockBehaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ Blockly.JavaScript["thread_import_variable"] = function (block) {

// makes a request from the parent to import a variable
var code = "";
code +=
inputVar +
" = await Handler.importVariable('" +
inputVar +
"');\n";
code += inputVar + " = await Handler.importVariable('" + inputVar + "');\n";
return code;
};

Expand All @@ -79,9 +75,11 @@ function generateWorkerImports() {
"if(typeof process === 'object'){\n" +
"\t_worker_code += `const {parentPort} = require('worker_threads')\\n`" +
"\t_worker_code += `const {Handler, consolelog, consoleerror, Message, RecvRequest} = require('./MessageHandler.js')\\n`\n" +
"\t_worker_code += `const Individual = require('./individual.js')\\n`\n" +
"\t_worker_code += `Handler.setParentPort(parentPort)\\n`" +
"}else{\n" +
"\t _worker_code += `importScripts(('` + globalThis.location + `').replace(/([^/]*$)/, '').replace('blob:', '') +'scripts/MessageHandler.js');\\n`\n" +
"\t _worker_code += `importScripts(('` + globalThis.location + `').replace(/([^/]*$)/, '').replace('blob:', '') +'scripts/individual.js');\\n`\n" +
"}\n"
);
}
Expand All @@ -105,7 +103,7 @@ function generateWorkerCode(statements, returnVal) {
PREV_DEFINITIONS = definitions;

workerCode += "async function mainFunction() {\n";
workerCode += " await Handler.resolveID();\n"
workerCode += " await Handler.resolveID();\n";

// execute the internal statements and return the value
workerCode += "`+`" + escapseString(statements) + "`+`;\n";
Expand Down
Loading