Skip to content

Instantly share code, notes, and snippets.

@psiphi75
Last active February 28, 2017 09:25
Show Gist options
  • Save psiphi75/80de0fb1e8af1d7be224c242b2d21149 to your computer and use it in GitHub Desktop.
Save psiphi75/80de0fb1e8af1d7be224c242b2d21149 to your computer and use it in GitHub Desktop.
Example of WebWorker worker
// This is our computation, we just initialise it for now.
var rt = new RayTracer(700, 700);
// we are in the worker.js thread so 'this' has the correct scope.
this.addEventListener('message', function(e) {
// Start the work
if (e.message === 'Start your work') {
var result = rt.raytrace();
// When we are done post the result
this.postMessage(result);
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment