Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Created October 2, 2020 08:33
Show Gist options
  • Save sverhoeven/001c241248d721a78f3033b350299ca3 to your computer and use it in GitHub Desktop.
Save sverhoeven/001c241248d721a78f3033b350299ca3 to your computer and use it in GitHub Desktop.
run-cpp-on-web: web-worker
importScripts('newtonraphson.js');
onmessage = function(message) {
if (message.data.type === 'CALCULATE') {
createModule().then(({NewtonRaphson}) => {
const tolerance = message.data.payload.tolerance;
const finder = new NewtonRaphson(tolerance);
const initial_guess = message.data.payload.initial_guess;
const root = finder.solve(initial_guess);
postMessage({
type: 'RESULT',
payload: {
root: root
}
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment