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]) if (this.noWait) {
.then(function (translator) { var loadPromise = this._loadTranslator(this.translator[0]);
this.translator[0] = translator; if (!loadPromise.isResolved()) {
var loadPromise = this._loadTranslator(translator); return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode"));
if (this.noWait) {
if (!loadPromise.isResolved()) {
return Zotero.Promise.reject(new Error("Load promise is not resolved in noWait mode"));
}
this._translateTranslatorLoaded();
} }
else { this._translateTranslatorLoaded();
loadPromise.then(() => this._translateTranslatorLoaded()); }
} else if (this.translator[0].then) {
}.bind(this)); Zotero.Promise.resolve(this.translator[0])
.then(function (translator) {
this.translator[0] = translator;
this._loadTranslator(translator).then(() => this._translateTranslatorLoaded());
}.bind(this));
}
else {
this._loadTranslator(this.translator[0]).then(() => this._translateTranslatorLoaded());
}
return deferred.promise; return deferred.promise;
}), }),