I have a file generation.js
and it has one main method that uses all of the other methods, but this method is super intensive and blocks the event loop. I have tried using a WebWorker class like:
class WebWorker {
constructor(worker) {
const code = worker.toString();
const blob = new Blob(['('+code+')()']);
return new Worker(URL.createObjectURL(blob));
}
}
To take this function and make it into a Web Worker so it can run separately, but it references other methods in its file and those aren't included in the scope. Is there a way to allow this method to access those methods without needing to turn the entire file into a Web Worker (by putting it in /public
and creating a Web Worker with its filename)?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…