]> git.parisson.com Git - pdf.js.git/commitdiff
Add a timeout before sending the pdf doc to the worker such that there is no too...
authorJulian Viereck <julian.viereck@gmail.com>
Sun, 9 Oct 2011 09:25:33 +0000 (11:25 +0200)
committerJulian Viereck <julian.viereck@gmail.com>
Sun, 9 Oct 2011 10:07:16 +0000 (12:07 +0200)
pdf.js

diff --git a/pdf.js b/pdf.js
index 2bb18864516f07dab9c69b5b09db551f10d88d8e..dfdada5ffaca08be2c9756fc0e2107133619ab16 100644 (file)
--- 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) {