aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/index.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/static/index.js b/static/index.js
index 53c20e6..600b638 100644
--- a/static/index.js
+++ b/static/index.js
@@ -64,9 +64,20 @@ function debounce(fn, delay) {
};
}
+let workerWorking = false;
+let queuedWork = undefined;
const worker = new Worker("worker.js", { type: "module" });
+function sendToWorker(code) {
+ if (workerWorking) {
+ queuedWork = code;
+ return;
+ }
+ worker.postMessage(code);
+}
+
worker.onmessage = (event) => {
+ // Handle the result of the compilation and execution
const result = event.data;
clearOutput();
if (result.log) appendOutput(result.log, "log");
@@ -74,6 +85,11 @@ worker.onmessage = (event) => {
for (const warning of result.warnings) {
appendOutput(warning, "warning");
}
+
+ // Deal with any queued work
+ workerWorking = false;
+ if (queuedWork) sendToWorker(queuedWork);
+ queuedWork = undefined;
};
editor.onUpdate(debounce((code) => worker.postMessage(code), 200));