Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
Created January 17, 2017 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackdouglas/68a4768c29f8928e1264b14e9db4b9c2 to your computer and use it in GitHub Desktop.
Save zackdouglas/68a4768c29f8928e1264b14e9db4b9c2 to your computer and use it in GitHub Desktop.
Launch a function as a Worker
function launchWorker(f) {
if (! (f instanceof Function)) {
throw new Error(`Cannot launch ${typeof(f)} as Worker`);
}
const src = `(${f})();`;
const blob = new Blob([src], {type: 'application/javascript'});
const url = URL.createObjectURL(blob);
return new Worker(url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment