mirror of https://github.com/pyodide/pyodide.git
Use promise for initialization. Use postRun hook to resolve.
This commit is contained in:
parent
93469d2996
commit
2a1a5b722e
|
@ -1,7 +1,6 @@
|
||||||
|
var languagePluginLoader = new Promise((resolve, reject) => {
|
||||||
{
|
|
||||||
let baseURL = "{{DEPLOY}}";
|
let baseURL = "{{DEPLOY}}";
|
||||||
let wasmURL = baseURL + 'pyodide.asm.wasm?x=' + Date.now();
|
let wasmURL = `${baseURL}pyodide.asm.wasm?x=${Date.now()}`;
|
||||||
let wasmXHR = new XMLHttpRequest();
|
let wasmXHR = new XMLHttpRequest();
|
||||||
wasmXHR.open('GET', wasmURL, true);
|
wasmXHR.open('GET', wasmURL, true);
|
||||||
wasmXHR.responseType = 'arraybuffer';
|
wasmXHR.responseType = 'arraybuffer';
|
||||||
|
@ -11,14 +10,21 @@
|
||||||
if (wasmXHR.status === 200 || wasmXHR.status === 0) {
|
if (wasmXHR.status === 200 || wasmXHR.status === 0) {
|
||||||
Module.wasmBinary = wasmXHR.response;
|
Module.wasmBinary = wasmXHR.response;
|
||||||
} else {
|
} else {
|
||||||
alert("Couldn't download the pyodide.asm.wasm binary. Response was " + wasmXHR.status);
|
alert(`Couldn't download the pyodide.asm.wasm binary. Response was ${wasmXHR.status}`);
|
||||||
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
Module.baseURL = baseURL;
|
Module.baseURL = baseURL;
|
||||||
var script = document.createElement('script');
|
Module.postRun = () => {
|
||||||
script.onload = function() { window.pyodide = pyodide(Module); };
|
resolve();
|
||||||
script.src = baseURL + "pyodide.asm.js";
|
}
|
||||||
|
let script = document.createElement('script');
|
||||||
|
script.src = `${baseURL}pyodide.asm.js`;
|
||||||
|
script.onload = () => {
|
||||||
|
window.pyodide = pyodide(Module);
|
||||||
|
};
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
};
|
};
|
||||||
wasmXHR.send(null);
|
wasmXHR.send(null);
|
||||||
}
|
});
|
||||||
|
languagePluginLoader
|
||||||
|
|
Loading…
Reference in New Issue