-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.js
More file actions
28 lines (22 loc) · 744 Bytes
/
python.js
File metadata and controls
28 lines (22 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const pythonWorker = new Worker("python-worker.js");
let _onPythonInitialized = null;
let pythonInitialized = new Promise((onSuccess) => _onPythonInitialized = onSuccess);
let _onReceivedCallback = null;
pythonWorker.onmessage = (event) => {
if (event.data == "initialized") {
_onPythonInitialized();
} else {
_onReceivedCallback(event.data);
}
};
documentUrl = document.URL;
// initialize worker
pythonWorker.postMessage({ documentUrl, micropipIncludePre, pythonModuleName });
async function jsConnect(receiveCallback) {
_onReceivedCallback = receiveCallback;
await pythonInitialized;
console.log("Python engine initialized!");
}
async function jsSend(data) {
pythonWorker.postMessage(data);
}