Created
October 2, 2020 08:33
-
-
Save sverhoeven/001c241248d721a78f3033b350299ca3 to your computer and use it in GitHub Desktop.
run-cpp-on-web: web-worker
This file contains hidden or 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
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