From 53b5a04a85e4c351f0d19e7593af8522ac1b6279 Mon Sep 17 00:00:00 2001 From: Chris Patuzzo Date: Fri, 19 Jan 2024 12:32:14 +0000 Subject: [PATCH] Print worker messages to the JavaScript console --- .../Editor/Runners/PyodideRunner/PyodideRunner.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Editor/Runners/PyodideRunner/PyodideRunner.jsx b/src/components/Editor/Runners/PyodideRunner/PyodideRunner.jsx index b036dfe7b..b2e6d0d35 100644 --- a/src/components/Editor/Runners/PyodideRunner/PyodideRunner.jsx +++ b/src/components/Editor/Runners/PyodideRunner/PyodideRunner.jsx @@ -1,7 +1,16 @@ +import { useMemo } from "react"; + const PyodideRunner = () => { - const worker = new Worker("/webworkers/pyodideWorker.js", { type: "module" }); + const worker = useMemo(loadPyodideWorker, []); + + worker.onmessage = ({ data }) => { + console.log(data); + }; return

Hello, World!

; }; +const loadPyodideWorker = () => + new Worker("/webworkers/pyodideWorker.js", { type: "module" }); + export default PyodideRunner;