0

I use web workers to calculate a bit of information in my application. And I don't want to kill the application with an increasing number of web workers so I need to limit creating new workers somehow.

My guess was that I could get a number of currently running workers. Is it possible?

Or maybe you can suggest any technique to limit creating of new ones? I was thinking about a global counter, but is it safe to use it with async workers?

1 Answer 1

1

Global counter is one way, allocating a dedicated array is another - something like for instance:

var workers = []; function spawnWorker(srcUrl) { if (workers.length < limit) { var worker = new Worker(srcUrl); workers.push(worker); ...setup handlers... return true; } else { return false; } } 

This way you will have easy access to the workers as well.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.