Przeglądaj źródła

improve shouldReconnectByCount

Yuki Takei 5 lat temu
rodzic
commit
707aaca965

+ 12 - 7
src/server/service/search-reconnect-context/reconnect-context.js

@@ -15,7 +15,7 @@ class ReconnectContext {
 
 
   reset() {
   reset() {
     this.counter = 0;
     this.counter = 0;
-    this.stage = 1;
+    this.stage = 0;
   }
   }
 
 
   incrementCount() {
   incrementCount() {
@@ -28,7 +28,8 @@ class ReconnectContext {
   }
   }
 
 
   get shouldReconnectByCount() {
   get shouldReconnectByCount() {
-    const thresholdOfThisStage = 10 * Math.log2(this.stage); // 0, 10, 15.9, 20, 23.2, 25.9, 28.1, 30, ...
+    // https://www.google.com/search?q=10log10(x)-1+graph
+    const thresholdOfThisStage = 10 * Math.log10(this.stage) - 1;
     return this.counter > thresholdOfThisStage;
     return this.counter > thresholdOfThisStage;
   }
   }
 
 
@@ -56,14 +57,18 @@ class ReconnectContext {
 
 
 }
 }
 
 
-async function nextTick(context, reconnectHandler) {
+function nextTick(context, reconnectHandler) {
   context.incrementCount();
   context.incrementCount();
 
 
   if (context.shouldReconnect) {
   if (context.shouldReconnect) {
-    await reconnectHandler();
-  }
-  else {
-    context.incrementStage();
+    const isSuccessToReconnect = reconnectHandler();
+
+    if (isSuccessToReconnect) {
+      context.reset();
+    }
+    else {
+      context.incrementStage();
+    }
   }
   }
 }
 }