zotero/resource/bluebird.js
Dan Stillman 0165f75f79 Stub Promise.defer() to avoid the Bluebird deprecation warnings
We should indeed use `new Zotero.Promise`, but we don't need the
warnings for existing code.
2019-08-27 00:47:39 -04:00

39 lines
No EOL
911 B
JavaScript

'use strict';
var EXPORTED_SYMBOLS = ['Promise'];
var Promise = require('bluebird/promise')();
Promise.config({
warnings: true,
longStackTraces: true,
cancellation: true
});
// Use our own stub to avoid the Bluebird deprecation warnings
Promise.defer = function() {
var deferred = {};
deferred.promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
return deferred;
}
// TEMP: Only turn on if debug logging enabled?
Promise.onPossiblyUnhandledRejection((e, promise) => {
if (e.name == 'ZoteroPromiseInterrupt' || e.handledRejection) {
return;
}
dump('Possibly unhandled rejection:\n\n'
+ (e.message
? e.message + "\n\n" + e.stack.split(/\n/)
// Filter out internal Bluebird calls
.filter(line => !line.includes('bluebird'))
.join('\n')
: e)
+ '\n');
throw e;
});
module.exports = Promise;