Skip to content

Instantly share code, notes, and snippets.

@psiphi75
Created February 28, 2017 09:07
Show Gist options
  • Save psiphi75/2e5b7bd41ed4533a7a03e78f6bfc3181 to your computer and use it in GitHub Desktop.
Save psiphi75/2e5b7bd41ed4533a7a03e78f6bfc3181 to your computer and use it in GitHub Desktop.
// ... continuing from code above.
// We create the worker, the work can actally begin (but will give the
// worker a message to start later).
var worker = new UniversalWorker(uri);
// Listen to all messages from the worker.
worker.addEventListener('message', waitForResult, { once: true });
// We send a message to the worker, this can be any primitive or object,
// including arrays.
worker.postMessage('Start your work');
function waitForResult(resultMessageFromWorker) {
// ... do something with the result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment