Add a InternalRenderTask.completed getter and use it to simplify PDFPageProxy._destroy

This patch aims to simplify the `PDFPageProxy._destroy` method, by:
 - Replacing the unnecessary `forEach` with a "regular" `for`-loop instead.
 - Use a more appropriate variable name, since `intentState.renderTasks` contain instances of `InternalRenderTask`.
 - Move the "is rendering completed"-handling to a new `InternalRenderTask.completed` getter, to abstract away some (mostly) internal `InternalRenderTask` state.
This commit is contained in:
Jonas Jenwald 2020-06-21 15:38:09 +02:00
parent a04a5d8325
commit cabc2cc4fc

View File

@ -1234,13 +1234,10 @@ class PDFPageProxy {
// Avoid errors below, since the renderTasks are just stubs. // Avoid errors below, since the renderTasks are just stubs.
return; return;
} }
intentState.renderTasks.forEach(function (renderTask) { for (const internalRenderTask of intentState.renderTasks) {
const renderCompleted = renderTask.capability.promise.catch( waitOn.push(internalRenderTask.completed);
function () {} internalRenderTask.cancel();
); // ignoring failures }
waitOn.push(renderCompleted);
renderTask.cancel();
});
}); });
this.objs.clear(); this.objs.clear();
this.annotationsPromise = null; this.annotationsPromise = null;
@ -2650,6 +2647,13 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this._canvas = params.canvasContext.canvas; this._canvas = params.canvasContext.canvas;
} }
get completed() {
return this.capability.promise.catch(function () {
// Ignoring errors, since we only want to know when rendering is
// no longer pending.
});
}
initializeGraphics(transparency = false) { initializeGraphics(transparency = false) {
if (this.cancelled) { if (this.cancelled) {
return; return;