From d313115d19b9388691a00416e5be9e41c4b5a933 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sun, 9 Oct 2011 11:25:33 +0200 Subject: [PATCH] Add a timeout before sending the pdf doc to the worker such that there is no too-long-js-running hint --- pdf.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index 2bb188645..dfdada5ff 100644 --- a/pdf.js +++ b/pdf.js @@ -4224,7 +4224,11 @@ var PDFDoc = (function() { WorkerProcessorHandler.setup(processorHandler); } - processorHandler.send('doc', this.data); + this.workerReadyPromise = new Promise('workerReady'); + setTimeout(function() { + processorHandler.send('doc', this.data); + this.workerReadyPromise.resolve(true); + }.bind(this)); } constructor.prototype = { @@ -4233,7 +4237,10 @@ var PDFDoc = (function() { }, startRendering: function(page) { - this.processorHandler.send('page_request', page.page.pageNumber + 1); + // The worker might not be ready to receive the page request yet. + this.workerReadyPromise.then(function() { + this.processorHandler.send('page_request', page.page.pageNumber + 1); + }.bind(this)); }, getPage: function(n) {