Created
July 12, 2018 18:08
-
-
Save shanewholloway/0f8a56b3abb9aefc9a9ee38f2067e309 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default asWorkerFunction | |
export asWorkerFunction | |
export asBlobURLFunction | |
function asWorkerFunction(func) { | |
return new Worker(asBlobURLFunction(func)) | |
} | |
function asBlobURLFunction(func) { | |
const rx_src = /(^.*=>|{)\s*([^]*?)(}\s*)?$/ | |
const f_src = rx_src.exec(func) | |
const blob = new Blob([f_src[2]]) | |
return URL.createObjectURL(blob) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asWorkerFunction from './asWorkerFunction.js' | |
asWorkerFunction(() => | |
self.postMessage({ | |
hello: Date.now(), | |
loc: location.toString(), | |
loc_hash: location.hash }) | |
).addEventListener('message', evt=>console.log('worker msg', evt.data), false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment