Просмотр исходного кода

fix: add delay for requests by default

close violentmonkey/violentmonkey#103
Gerald 8 лет назад
Родитель
Сommit
d60424addc
2 измененных файлов с 8 добавлено и 8 удалено
  1. 7 7
      src/background/sync/base.js
  2. 1 1
      src/background/sync/onedrive.js

+ 7 - 7
src/background/sync/base.js

@@ -238,14 +238,14 @@ export const BaseService = serviceFactory({
   },
   loadData(options) {
     const { progress } = this;
-    let lastFetch;
-    if (options.delay == null) {
-      lastFetch = Promise.resolve(Date.now());
-    } else {
+    let { delay } = options;
+    if (delay == null) {
+      delay = this.delayTime;
+    }
+    let lastFetch = Promise.resolve();
+    if (delay) {
       lastFetch = this.lastFetch
       .then(ts => new Promise(resolve => {
-        let delay = options.delay;
-        if (!isNaN(delay)) delay = this.delayTime;
         const delta = delay - (Date.now() - ts);
         if (delta > 0) {
           setTimeout(resolve, delta);
@@ -254,8 +254,8 @@ export const BaseService = serviceFactory({
         }
       }))
       .then(() => Date.now());
+      this.lastFetch = lastFetch;
     }
-    this.lastFetch = lastFetch;
     progress.total += 1;
     onStateChange();
     return lastFetch.then(() => {

+ 1 - 1
src/background/sync/onedrive.js

@@ -75,7 +75,7 @@ const OneDrive = BaseService.extend({
     })
     .then(data => this.loadData({
       url: data['@content.downloadUrl'],
-      delay: 0,
+      delay: false,
     }));
   },
   put(path, data) {