Im trying to create web Workers and post messages to them in cycle:
array.forEach(function (data) {
this.createWorker();
this.workers[this.workersPointer].postMessage({task: 'someTask', data: string});
}, this);
createWorker function:
createWorker: function () {
this.workersPointer++;
var worker = this.workers[this.workersPointer] = new Worker('Worker.js'),
storage = this;
worker.onmessage = function (event) {
if (event.data.error) {
storage[event.data.task + 'Errback'](event.data.error);
}
else {
storage[event.data.task + 'Callback'](event.data.data);
}
};
worker.onerror = function (error) {
storage.workerErrback(error);
};
}
Worker code:
self.addEventListener('message', function (event) {
self.postMessage({
data: data,
error: err,
task: event.data.task
});
}, false);
It works perfectly in Google Chrome. When I'm trying to run it in Firefox, it works only 20 times. Do Firefox web workers have a limit? I can't find information about it on mozilla.org. If there is no limit, what's the problem? Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…