Skip to content

Commit

Permalink
Workers can log to the console just fine.
Browse files Browse the repository at this point in the history
Did you mean to say something else?
  • Loading branch information
greggman committed Oct 28, 2023
1 parent 7349a25 commit 49368c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/sample/worker/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
7 changes: 3 additions & 4 deletions src/sample/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 49368c2

Please sign in to comment.