[next] Improved worker attribute DX (#1625)

This commit is contained in:
Andrea Giammarchi
2023-08-07 18:36:33 +02:00
committed by GitHub
parent a484aff457
commit 77d8fe3562
10 changed files with 79 additions and 73 deletions

View File

@@ -101,6 +101,28 @@ const registerModule = ({ XWorker: $XWorker, interpreter, io }) => {
});
};
export const hooks = {
/** @type {Set<function>} */
onBeforeRun: new Set(),
/** @type {Set<function>} */
onBeforeRunAync: new Set(),
/** @type {Set<function>} */
onAfterRun: new Set(),
/** @type {Set<function>} */
onAfterRunAsync: new Set(),
/** @type {Set<function>} */
onInterpreterReady: new Set(),
/** @type {Set<string>} */
codeBeforeRunWorker: new Set(),
/** @type {Set<string>} */
codeBeforeRunWorkerAsync: new Set(),
/** @type {Set<string>} */
codeAfterRunWorker: new Set(),
/** @type {Set<string>} */
codeAfterRunWorkerAsync: new Set(),
};
const workerPyScriptModule = [
"from pyodide_js import FS",
`FS.writeFile('./pyscript.py', '${[
@@ -210,25 +232,3 @@ export function PyWorker(file, options) {
type: "pyodide",
});
}
export const hooks = {
/** @type {Set<function>} */
onBeforeRun: new Set(),
/** @type {Set<function>} */
onBeforeRunAync: new Set(),
/** @type {Set<function>} */
onAfterRun: new Set(),
/** @type {Set<function>} */
onAfterRunAsync: new Set(),
/** @type {Set<function>} */
onInterpreterReady: new Set(),
/** @type {Set<string>} */
codeBeforeRunWorker: new Set(),
/** @type {Set<string>} */
codeBeforeRunWorkerAsync: new Set(),
/** @type {Set<string>} */
codeAfterRunWorker: new Set(),
/** @type {Set<string>} */
codeAfterRunWorkerAsync: new Set(),
};