From 49368c2fb63c18fe705d56dd0ddbb9b573e1f55d Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Sun, 29 Oct 2023 08:13:14 +0900 Subject: [PATCH] Workers can log to the console just fine. Did you mean to say something else? --- src/sample/worker/main.ts | 6 ------ src/sample/worker/worker.ts | 7 +++---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/sample/worker/main.ts b/src/sample/worker/main.ts index 4a2cc95f..30ce76c5 100644 --- a/src/sample/worker/main.ts +++ b/src/sample/worker/main.ts @@ -14,12 +14,6 @@ const init: SampleInit = async ({ canvas, pageState }) => { // complexity. Here we establish a convention that all messages to and from the worker will // have a `type` field that we can use to determine the content of the message. switch (ev.data.type) { - case 'log': { - // Workers don't have a built-in mechanism for logging to the console, so it's useful to - // create a way to echo console messages. - console.log(ev.data.message); - break; - } default: { console.error(`Unknown Message Type: ${ev.data.type}`); } diff --git a/src/sample/worker/worker.ts b/src/sample/worker/worker.ts index 2d26c45f..c71d9d20 100644 --- a/src/sample/worker/worker.ts +++ b/src/sample/worker/worker.ts @@ -21,10 +21,9 @@ self.addEventListener('message', (ev) => { try { init(ev.data.offscreenCanvas); } catch (err) { - self.postMessage({ - type: 'log', - message: `Error while initializing WebGPU in worker process: ${err.message}`, - }); + console.error( + `Error while initializing WebGPU in worker process: ${err.message}` + ); } break; }