Worker sync utility (#1511)

* patched an issue with wasmoon randomly asking to resolve proxy references
  * simplified pyodide and micropython dance by grouping their common utilities together
  * created an integration test around a worker to main thread input between MicroPython and Lua
  * commented some weird bugs / funny behaviors around both MicroPython and Pyodide
  * other minor clean ups
This commit is contained in:
Andrea Giammarchi
2023-06-08 11:10:47 +02:00
committed by GitHub
parent 0cdbfbeb30
commit af72e232c3
26 changed files with 277 additions and 81 deletions

View File

@@ -1,15 +1,17 @@
import { clean, fetchPaths, stdio, writeFile } from "./_utils.js";
import { fetchPaths, stdio } from "./_utils.js";
import {
run,
runAsync,
runEvent,
runWorker,
runWorkerAsync,
writeFile,
} from "./_python.js";
const type = "micropython";
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const worker = (method) =>
function (runtime, code, xworker) {
globalThis.xworker = xworker;
return this[method](runtime, `from js import xworker;${code}`);
};
export default {
type: [type, "mpy"],
module: () => `http://localhost:8080/micropython/micropython.mjs`,
@@ -20,16 +22,11 @@ export default {
if (config.fetch) await fetchPaths(this, runtime, config.fetch);
return runtime;
},
run: (runtime, code) => runtime.runPython(clean(code)),
runAsync: (runtime, code) => runtime.runPythonAsync(clean(code)),
runEvent(runtime, code, key) {
return this.run(
runtime,
`import js;event=js.__events.get(${key});${code}`,
);
},
runWorker: worker("run"),
runWorkerAsync: worker("runAsync"),
writeFile: ({ FS }, path, buffer) => writeFile(FS, path, buffer),
run,
runAsync,
runEvent,
runWorker,
runWorkerAsync,
writeFile,
};
/* c8 ignore stop */