Skip to content

Instantly share code, notes, and snippets.

@MattiasFestin
Created May 11, 2015 09:14
Show Gist options
  • Save MattiasFestin/9aa83ea041dc86265408 to your computer and use it in GitHub Desktop.
Save MattiasFestin/9aa83ea041dc86265408 to your computer and use it in GitHub Desktop.
Spawn webworker with function or js code in string
let spawn = (...args) => {
var src = args.map(function (x) {
return typeof x === 'function' ? '((' + x.toString() + ').call(this));' : x;
}).join(';');
return new Worker(
window.URL.createObjectURL(
new Blob([src])
)
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment