Files
iD/modules/util/idle_worker.js
Bryan Housel 0c0ecdfcfc Comment out some of the requestIdleCallback to fix walkthrough crash
(closes #4533)

There are several issues here.. Here's a quick brain dump:

- the requestIdleCallbacks in map.js (scheduleRedraw) seem to be causing
crashiness in Firefox on fast zoom/unzoom, mousewheel, etc.. anything where
the view transform changes a lot and the redraws don't catch up.
(commented out, reverted back to lodash throttle)

- the requestIdleCallback worker queue in idle_worker.js seems to be causing
crashiness in Firefox and Chrome when exiting the walkthrough.  Something about
deferring the tile parsing as the user leaves the intro has a problem.
It might be an infinite `while` loop, not sure.
(commented out, reverted back to for loop)

- the requestIdleCallback in call_when_idle.js is only used to defer
tile loading in context.loadTiles() - this one seems fine, and actually
has maybe the biggest benefit for improving performance.
(left in)
2017-11-15 22:21:40 -05:00

54 lines
1.5 KiB
JavaScript

export function utilIdleWorker(tasks, processor, callback) {
var results = [], result;
for (var i = 0; i < tasks.length; i++) {
result = processor(tasks[i]);
if (result) results.push(result);
}
callback(results);
// var processed = [];
// var currentPos = 0;
// var totalTasks = tasks.length;
// function worker(deadline) {
// while (deadline.timeRemaining() > 0 && currentPos < totalTasks) {
// var result = processor(tasks[currentPos]);
// // if falsy dont add to the processed list
// if (result) processed.push(result);
// currentPos++;
// }
// // more tasks are left, we might need more idleCallbacks
// if (currentPos < totalTasks) {
// return window.requestIdleCallback(function(deadline) {worker(deadline);});
// }
// // tasks are completed
// return callback(processed);
// }
// window.requestIdleCallback(function(deadline) {worker(deadline);});
}
// shim
window.requestIdleCallback =
window.requestIdleCallback ||
function(cb) {
var start = Date.now();
return setTimeout(function() {
cb({
didTimeout: false,
timeRemaining: function() {
return Math.max(0, 50 - (Date.now() - start));
}
});
}, 1);
};
window.cancelIdleCallback =
window.cancelIdleCallback ||
function(id) {
clearTimeout(id);
};