Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

javascript - Allow a Web Worker to use other functions in a React App

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)?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...