Last active
July 27, 2020 15:25
-
-
Save christianlavoie/db264f799ef10638d102259e10d188f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as rts from "./_build/rts.mjs"; | |
import module from "./_build/Main.wasm.mjs"; | |
import req from "./_build/Main.req.mjs"; | |
module.then(m => | |
rts.newAsteriusInstance(Object.assign(req, {module: m}))) | |
.then(i => { | |
i.exports.main() | |
.catch(err => { | |
if (!(err.startsWith('ExitSuccess') || err.startsWith('ExitFailure '))) | |
i.fs.writeSync(2, `Main: ${err}`) | |
}); | |
self.postMessage(['INITIALIZED'].concat(Object.keys(i.exports))); | |
self.onmessage = function(e) { | |
self.postMessage(['RECEIVED'].concat(e.data)); | |
if (e.data[0] == 'calc') { | |
let p = i.exports.runParser(e.data[1]); | |
p.then(v => { | |
self.postMessage(['CALC VALUE', (' ' + v).slice(1)]) | |
}).catch(r => { | |
self.postMessage(['CALC CRASH', (' ' + r).slice(1)]) | |
}); | |
} else { | |
self.postMessage(['RECEIVED UNKNOWN MESSAGE'].concat(e.data)); | |
} | |
}; | |
setInterval(function () { | |
let stdout = i.stdio.stdout(); | |
if (stdout != "") self.postMessage(['STDOUT', stdout]); | |
let stderr = i.stdio.stderr(); | |
if (stderr != "") self.postMessage(['STDERR', stderr]); | |
}, 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment