Merge pull request #7829 from Snuffleupagus/finishPaintTask-promise

Let `finishPaintTask` in pdf_page_view.js return a promise instead, to avoid having to throw in the `paintTask.promise` rejection handler, and don't reject the `PDFPageView_draw` promise when rendering is `cancelled`
This commit is contained in:
Tim van der Meij 2016-12-27 23:51:06 +01:00 committed by GitHub
commit 22f0a04df0

View File

@ -423,7 +423,7 @@ var PDFPageView = (function PDFPageViewClosure() {
if (error === 'cancelled') { if (error === 'cancelled') {
self.error = null; self.error = null;
return; return Promise.resolve(undefined);
} }
self.renderingState = RenderingStates.FINISHED; self.renderingState = RenderingStates.FINISHED;
@ -459,6 +459,11 @@ var PDFPageView = (function PDFPageViewClosure() {
pageNumber: self.id, pageNumber: self.id,
cssTransform: false, cssTransform: false,
}); });
if (error) {
return Promise.reject(error);
}
return Promise.resolve(undefined);
}; };
var paintTask = this.renderer === RendererType.SVG ? var paintTask = this.renderer === RendererType.SVG ?
@ -468,7 +473,7 @@ var PDFPageView = (function PDFPageViewClosure() {
this.paintTask = paintTask; this.paintTask = paintTask;
var resultPromise = paintTask.promise.then(function () { var resultPromise = paintTask.promise.then(function () {
finishPaintTask(null); return finishPaintTask(null).then(function () {
if (textLayer) { if (textLayer) {
pdfPage.getTextContent({ pdfPage.getTextContent({
normalizeWhitespace: true, normalizeWhitespace: true,
@ -477,9 +482,9 @@ var PDFPageView = (function PDFPageViewClosure() {
textLayer.render(TEXT_LAYER_RENDER_DELAY); textLayer.render(TEXT_LAYER_RENDER_DELAY);
}); });
} }
});
}, function (reason) { }, function (reason) {
finishPaintTask(reason); return finishPaintTask(reason);
throw reason;
}); });
if (this.annotationLayerFactory) { if (this.annotationLayerFactory) {