Skip to content

Instantly share code, notes, and snippets.

@weihanglo
Created June 17, 2017 00:38
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 weihanglo/0a9b2f8229bd016a867ede334eb34d0f to your computer and use it in GitHub Desktop.
Save weihanglo/0a9b2f8229bd016a867ede334eb34d0f to your computer and use it in GitHub Desktop.
Inline web worker
const blobURL = URL.createObjectURL(new Blob([ '(',
function () {
function fibonacci () {}
onmessage = function (ev) {
const result = processData(ev.data)
postMessage(result)
}
}.toString(),
')()' ], { type: 'application/javascript' } )
)
const worker = new Worker(blobURL);
worker.onmessage = function (ev) {
console.log(`Receive result: ${ev.data}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment