switch from Sync.sleep() back to a generator (although a custom one rather than Strands this time) in the river view to avoid the long-running script warning, which unfortunately gets applied to chrome code in tabs and can't distinguish between long-running code that horks the UI thread and code (like that in the river view) that spins the event loop so as not to hork the thread

This commit is contained in:
Myk Melez 2009-09-13 19:13:40 -07:00
Родитель 8a496f5c18
Коммит 3c8abaabb5
1 изменённых файлов: 28 добавлений и 13 удалений

Просмотреть файл

@ -762,38 +762,53 @@ this._log.info("onMessageAdded: REFRESH RIVER");
_rebuildID: null,
_rebuildView: function() {
let begin = new Date();
let rebuildID = this._rebuildID = Cc["@mozilla.org/uuid-generator;1"].
getService(Ci.nsIUUIDGenerator).
generateUUID().toString();
let generator = this._makeRebuildViewGenerator();
// Reset the view by removing all its groups and messages.
// Reset the view by removing all its message boxes.
// XXX Since contentBox is an HTML div, could we do this more quickly
// by setting innerHTML to an empty string?
while (this._contentBox.hasChildNodes())
this._contentBox.removeChild(this._contentBox.lastChild);
// Build the box for each message and add it to the view.
(function() {
try {
let timeout = generator.next();
window.setTimeout(arguments.callee, timeout);
}
catch(ex if ex == StopIteration) {}
})()
},
_makeRebuildViewGenerator: function() {
let first = new Date();
let rebuildID = this._rebuildID = Cc["@mozilla.org/uuid-generator;1"].
getService(Ci.nsIUUIDGenerator).
generateUUID().toString();
this._log.trace("started rebuild " + rebuildID);
for each (let message in this._collection) {
let before = new Date();
let messageBox = this._buildMessageBox(message);
this._contentBox.appendChild(messageBox);
this._contentBox.appendChild(this._buildMessageBox(message));
let after = new Date();
let timeout = this._rebuildViewTimeout;
this._log.trace("last: " + (after - before) + "ms; " +
this._log.trace("rebuild stats: " +
"last: " + (after - before) + "ms; " +
"total: " + (after - first) + "ms; " +
"timeout: " + timeout + "ms");
Sync.sleep(timeout);
yield timeout;
// Stop rebuilding if another rebuild started while we were sleeping.
// Stop the rebuild if another rebuild started while we were yielded.
if (this._rebuildID != rebuildID) {
this._log.debug(this._rebuildID + " != " + rebuildID + "; stopping rebuild");
this._log.trace("interrupted rebuild " + rebuildID + " for rebuild " +
this._rebuildID);
return;
}
}
this._log.info("time spent building view: " + (new Date() - begin) + "ms\n");
let last = new Date();
this._log.trace("finished rebuild " + rebuildID + " in " +
((last - first)/1000) + " seconds)");
},
_buildMessageBox: function(message) {