Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Created October 2, 2020 10:11
Show Gist options
  • Save sverhoeven/42230347c3b0c511b501184faa28d6ae to your computer and use it in GitHub Desktop.
Save sverhoeven/42230347c3b0c511b501184faa28d6ae to your computer and use it in GitHub Desktop.
run-cpp-on-web: kitchen-sink
const [result, setResult] = React.useState({ root: undefined, iterations: [] });
function handleSubmit(event) {
event.preventDefault();
const worker = new Worker('worker.js');
worker.onmessage = function (message) {
if (message.data.type === 'RESULT') {
const result = message.data.payload;
setResult(result);
worker.terminate();
}
};
worker.postMessage({
type: 'CALCULATE',
payload: { tolerance: tolerance, initial_guess: initial_guess }
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment