Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. function launchWorker(f) {
  2. if (! (f instanceof Function)) {
  3. throw new Error(`Cannot launch ${typeof(f)} as Worker`);
  4. }
  5. const src = `(${f})();`;
  6. const blob = new Blob([src], {type: 'application/javascript'});
  7. const url = URL.createObjectURL(blob);
  8. return new Worker(url);
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement