Remove use of Promise.tap() from Bluebird and our own Promise.check()

This commit is contained in:
Dan Stillman 2022-02-21 15:45:50 -05:00
parent e48d069687
commit ca3fd80825
3 changed files with 12 additions and 28 deletions

View file

@ -306,8 +306,9 @@
// Page count
if (this.displayPages) {
Zotero.Fulltext.getPages(this.item.id)
.tap(() => Zotero.Promise.check(this.item))
.then(function (pages) {
if (!this.item) return;
pages = pages ? pages.total : null;
if (pages) {
this._id("pages-label").value = Zotero.getString('itemFields.pages')
@ -337,8 +338,9 @@
}
else {
this.item.attachmentModificationTime
.tap(() => Zotero.Promise.check(this._id))
.then(function (mtime) {
if (!this._id) return;
if (mtime) {
this._id("dateModified").value = new Date(mtime).toLocaleString();
}
@ -353,10 +355,10 @@
// Full-text index information
if (this.displayIndexed) {
this.updateItemIndexedState()
.tap(() => Zotero.Promise.check(this.item))
.then(function () {
if (!this.item) return;
indexStatusRow.hidden = false;
});
}.bind(this));
}
else {
indexStatusRow.hidden = true;
@ -533,8 +535,9 @@
var indexStatus = this._id('index-status');
var reindexButton = this._id('reindex');
var status = yield Zotero.Fulltext.getIndexedState(this.item)
.tap(() => Zotero.Promise.check(this.item));
var status = yield Zotero.Fulltext.getIndexedState(this.item);
if (!this.item) return;
var str = 'fulltext.indexState.';
switch (status) {
case Zotero.Fulltext.INDEX_STATE_UNAVAILABLE:
@ -563,8 +566,8 @@
var show = false;
if (this.editable) {
show = yield Zotero.Fulltext.canReindex(this.item)
.tap(() => Zotero.Promise.check(this.item));
show = yield Zotero.Fulltext.canReindex(this.item);
if (!this.item) return;
}
if (show) {

View file

@ -172,25 +172,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
this.uiReadyDeferred = Zotero.Promise.defer();
this.uiReadyPromise = this.uiReadyDeferred.promise;
// Add a function to Zotero.Promise to check whether a value is still defined, and if not
// to throw a specific error that's ignored by the unhandled rejection handler in
// bluebird.js. This allows for easily cancelling promises when they're no longer
// needed, for example after a binding is destroyed.
//
// Example usage:
//
// getAsync.tap(() => Zotero.Promise.check(this.mode))
//
// If the binding is destroyed while getAsync() is being resolved and this.mode no longer
// exists, subsequent lines won't be run, and nothing will be logged to the console.
this.Promise.check = function (val) {
if (!val && val !== 0) {
let e = new Error;
e.name = "ZoteroPromiseInterrupt";
throw e;
}
};
if (options) {
let opts = [
'openPane',

View file

@ -21,7 +21,7 @@ Promise.defer = function() {
}
// TEMP: Only turn on if debug logging enabled?
Promise.onPossiblyUnhandledRejection((e, promise) => {
if (e.name == 'ZoteroPromiseInterrupt' || e.handledRejection) {
if (e.handledRejection) {
return;
}