[Pkg-javascript-commits] [pdf.js] 118/161: Makes sure the results are send /handled in right order

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 14:16:36 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 567f1f4af0cf5013f002dbe8edfc992b048fa806
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Tue Mar 25 07:29:53 2014 -0500

    Makes sure the results are send /handled in right order
---
 test/driver.js | 67 +++++++++++++++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/test/driver.js b/test/driver.js
index 0c41988..6602f14 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -232,10 +232,11 @@ function nextPage(task, loadError) {
   var failure = loadError || '';
 
   if (!task.pdfDoc) {
-    sendTaskResult(canvasToDataURL(), task, failure);
-    log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
-    ++currentTaskIdx;
-    nextTask();
+    sendTaskResult(canvasToDataURL(), task, failure, function () {
+      log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
+      ++currentTaskIdx;
+      nextTask();
+    });
     return;
   }
 
@@ -332,18 +333,12 @@ function nextPage(task, loadError) {
 function snapshotCurrentPage(task, failure) {
   log('done, snapshotting... ');
 
-  sendTaskResult(canvasToDataURL(), task, failure);
-  log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
-
-  // Set up the next request
-  var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
-  setTimeout(
-    function snapshotCurrentPageSetTimeout() {
-      ++task.pageNum;
-      nextPage(task);
-    },
-    backoff
-  );
+  sendTaskResult(canvasToDataURL(), task, failure, function () {
+    log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
+
+    ++task.pageNum;
+    nextPage(task);
+  });
 }
 
 function sendQuitRequest() {
@@ -373,28 +368,25 @@ function done() {
   }
 }
 
-function sendTaskResult(snapshot, task, failure, result) {
-  // Optional result argument is for retrying XHR requests - see below
-  if (!result) {
-    result = JSON.stringify({
-      browser: browser,
-      id: task.id,
-      numPages: task.pdfDoc ?
-               (task.lastPage || task.pdfDoc.numPages) : 0,
-      lastPageNum: getLastPageNum(task),
-      failure: failure,
-      file: task.file,
-      round: task.round,
-      page: task.pageNum,
-      snapshot: snapshot,
-      stats: task.stats.times
-    });
-  }
-
-  send('/submit_task_results', result);
+function sendTaskResult(snapshot, task, failure, callback) {
+  var result = JSON.stringify({
+    browser: browser,
+    id: task.id,
+    numPages: task.pdfDoc ?
+             (task.lastPage || task.pdfDoc.numPages) : 0,
+    lastPageNum: getLastPageNum(task),
+    failure: failure,
+    file: task.file,
+    round: task.round,
+    page: task.pageNum,
+    snapshot: snapshot,
+    stats: task.stats.times
+  });
+
+  send('/submit_task_results', result, callback);
 }
 
-function send(url, message) {
+function send(url, message, callback) {
   var r = new XMLHttpRequest();
   // (The POST URI is ignored atm.)
   r.open('POST', url, true);
@@ -408,6 +400,9 @@ function send(url, message) {
           send(url, message);
         });
       }
+      if (callback) {
+        callback();
+      }
     }
   };
   document.getElementById('inFlightCount').innerHTML = inFlightRequests++;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list