Skip to content

Instantly share code, notes, and snippets.

@Legends
Created November 2, 2019 21:48
Show Gist options
  • Select an option

  • Save Legends/2c8e3e9500df14794de8f7f9e56c2d7a to your computer and use it in GitHub Desktop.

Select an option

Save Legends/2c8e3e9500df14794de8f7f9e56c2d7a to your computer and use it in GitHub Desktop.
// *************************** Main.js **********************************
var worker = new Worker('/Scripts/fileupload.js'); // fileupload.js is our webworker script file
worker.onmessage = (e) => { // called when ww calls self.postMessage
console.log(e.data);
};
worker.onerror = (e) => { // onerror
console.log('ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message);
}
worker.postMessage({ 'files': files }); // calls self.onmessagein the ww
worker.terminate(); // called to terminate the ww
// *************************** fileupload.js (WebWorker) **********************************
self.onmessage = (e) => { // ww receives message
for (var j = 0; j < e.data.files.length; j++)
files.push(e.data.files[j]);
if (p) {
process();
}
};
// calls worker.onmessage
// ww posts message back to page or script which created the ww
self.postMessage(blob.name + " Uploaded Succesfully");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment