Fix noWait translation mode (broken by e3a9c6779b)

This commit is contained in:
Dan Stillman 2016-09-06 02:17:20 -04:00
parent e3a9c6779b
commit ca833f54fc

View file

@ -1262,25 +1262,29 @@ Zotero.Translate.Base.prototype = {
this.translator[0] = Zotero.Translators.get(this.translator[0]); this.translator[0] = Zotero.Translators.get(this.translator[0]);
} }
// Zotero.Translators.get() returns a promise in the connectors // Zotero.Translators.get() returns a promise in the connectors, but we don't expect it to
if (this.noWait && this.translator[0].then && !this.translator[0].isResolved()) { // otherwise
throw new Error("Translator promise is not resolved in noWait mode"); if (!this.isConnector && this.translator[0].then) {
throw new Error("Translator should not be a promise in non-connector mode");
} }
Zotero.Promise.resolve(this.translator[0])
.then(function (translator) {
this.translator[0] = translator;
var loadPromise = this._loadTranslator(translator);
if (this.noWait) { if (this.noWait) {
var loadPromise = this._loadTranslator(this.translator[0]);
if (!loadPromise.isResolved()) { if (!loadPromise.isResolved()) {
return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode")); return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode"));
} }
this._translateTranslatorLoaded(); this._translateTranslatorLoaded();
} }
else { else if (this.translator[0].then) {
loadPromise.then(() => this._translateTranslatorLoaded()); Zotero.Promise.resolve(this.translator[0])
} .then(function (translator) {
this.translator[0] = translator;
this._loadTranslator(translator).then(() => this._translateTranslatorLoaded());
}.bind(this)); }.bind(this));
}
else {
this._loadTranslator(this.translator[0]).then(() => this._translateTranslatorLoaded());
}
return deferred.promise; return deferred.promise;
}), }),