make applyCommands asynchronous

This commit is contained in:
Dan Mills 2008-03-26 23:11:15 -07:00
Родитель a7291a69bd
Коммит 332279d554
2 изменённых файлов: 17 добавлений и 3 удалений

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

@ -337,10 +337,12 @@ Engine.prototype = {
// Note that we need to need to apply client changes to the
// current tree, not the saved snapshot
localJson.applyCommands(clientChanges);
localJson.applyCommands.async(localJson, self.cb, clientChanges);
yield;
this._snapshot.data = localJson.data;
this._snapshot.version = server.maxVersion;
this._store.applyCommands(clientChanges);
this._store.applyCommands.async(this._store, self.cb, clientChanges);
yield;
newSnapshot = this._store.wrap();
this._core.detectUpdates(self.cb, this._snapshot.data, newSnapshot);
@ -570,7 +572,8 @@ Engine.prototype = {
}
for (var i = 0; i < deltas.length; i++) {
snap.applyCommands(deltas[i]);
snap.applyCommands.async(snap, self.cb, deltas[i]);
yield;
}
ret.status = 0;

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

@ -57,6 +57,7 @@ function Store() {
}
Store.prototype = {
_logName: "Store",
_yieldDuringApply: true,
__json: null,
get _json() {
@ -71,7 +72,16 @@ Store.prototype = {
},
applyCommands: function Store_applyCommands(commandList) {
let self = yield;
if (this._yieldDuringApply)
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
for (var i = 0; i < commandList.length; i++) {
if (this._yieldDuringApply) {
timer.initWithCallback(listener, 0, timer.TYPE_ONE_SHOT);
yield; // Yield to main loop
}
var command = commandList[i];
this._log.debug("Processing command: " + this._json.encode(command));
switch (command["action"]) {
@ -89,6 +99,7 @@ Store.prototype = {
break;
}
}
self.done();
},
// override these in derived objects