Change waitOnEventOrTimeout
, in web/ui_utils.js, to return a regular Promise
and remove the createPromiseCapability
import
*Another small piece of clean-up of code I've previously written; follow-up to PR 8775.* Importing `createPromiseCapability`, and then using it in just *one* spot, seems unnecessary since the `waitOnEventOrTimeout` function may just as well return a regular `Promise` directly.
This commit is contained in:
parent
61db85ab64
commit
647fa74793
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPromiseCapability } from 'pdfjs-lib';
|
||||
|
||||
const CSS_UNITS = 96.0 / 72.0;
|
||||
const DEFAULT_SCALE_VALUE = 'auto';
|
||||
const DEFAULT_SCALE = 1.0;
|
||||
@ -634,12 +632,11 @@ const WaitOnType = {
|
||||
* @returns {Promise} A promise that is resolved with a {WaitOnType} value.
|
||||
*/
|
||||
function waitOnEventOrTimeout({ target, name, delay = 0, }) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof target !== 'object' || !(name && typeof name === 'string') ||
|
||||
!(Number.isInteger(delay) && delay >= 0)) {
|
||||
return Promise.reject(
|
||||
new Error('waitOnEventOrTimeout - invalid parameters.'));
|
||||
throw new Error('waitOnEventOrTimeout - invalid parameters.');
|
||||
}
|
||||
let capability = createPromiseCapability();
|
||||
|
||||
function handler(type) {
|
||||
if (target instanceof EventBus) {
|
||||
@ -651,20 +648,19 @@ function waitOnEventOrTimeout({ target, name, delay = 0, }) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
capability.resolve(type);
|
||||
resolve(type);
|
||||
}
|
||||
|
||||
let eventHandler = handler.bind(null, WaitOnType.EVENT);
|
||||
const eventHandler = handler.bind(null, WaitOnType.EVENT);
|
||||
if (target instanceof EventBus) {
|
||||
target.on(name, eventHandler);
|
||||
} else {
|
||||
target.addEventListener(name, eventHandler);
|
||||
}
|
||||
|
||||
let timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
|
||||
const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
|
||||
let timeout = setTimeout(timeoutHandler, delay);
|
||||
|
||||
return capability.promise;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user