Bug 1572467 - Don't call successCallback again once it succeeds. r=BenB a=jorgk
authorneil@parkwaycc.co.uk <neil@parkwaycc.co.uk>
Tue, 13 Aug 2019 20:11:29 +0200
changeset 35754 c3317cbda62d9f7b6197302fe66acc784c214ff0
parent 35753 9c2141de871f14541b45812c40c863f6798c8f28
child 35755 1b43445ce5f59d9932741c5abd188f6ece733afe
push id17
push usermozilla@jorgk.com
push dateWed, 28 Aug 2019 13:49:07 +0000
treeherdercomm-esr68@d788b4098371 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenB, jorgk
bugs1572467
Bug 1572467 - Don't call successCallback again once it succeeds. r=BenB a=jorgk
mail/components/accountcreation/content/util.js
--- a/mail/components/accountcreation/content/util.js
+++ b/mail/components/accountcreation/content/util.js
@@ -371,51 +371,51 @@ ParallelCall.prototype = {
  *     {Exception} e - The exception returned by the first call.
  *     This is just to adhere to the standard API of errorCallback(e).
  *     {Array of Exception} allErrors - The exceptions from all calls.
  */
 function PriorityOrderAbortable(successCallback, errorCallback) {
   assert(typeof(successCallback) == "function");
   assert(typeof(errorCallback) == "function");
   ParallelAbortable.call(this); // call super constructor
+  this._successfulCall = null;
 
   this.addOneFinishedObserver(finishedCall => {
-    let haveHigherSuccess = false;
     for (let call of this._calls) {
       if (!call.finished) {
-        if (haveHigherSuccess) {
+        if (this._successfulCall) {
           // abort
           if (call.callerAbortable) {
             call.callerAbortable.cancel(NoLongerNeededException("Another higher call succeeded"));
           }
           continue;
         }
         // It's pending. do nothing and wait for it.
         return;
       }
       if (!call.succeeded) {
         // it failed. ignore it.
         continue;
       }
-      if (haveHigherSuccess) {
-        // another successful call was higher. ignore it.
+      if (this._successfulCall) {
+        // we already have a winner. ignore it.
         continue;
       }
-      // This is the winner.
       try {
         successCallback(call.result, call);
-        haveHigherSuccess = true;
+        // This is the winner.
+        this._successfulCall = call;
       } catch (e) {
         console.error(e);
         // If the handler failed with this data, treat this call as failed.
         call.e = e;
         call.succeeded = false;
       }
     }
-    if (!haveHigherSuccess) {
+    if (!this._successfulCall) {
       // all failed
       errorCallback(this._calls[0].e, this._calls.map(call => call.e)); // see docs above
     }
   });
 }
 PriorityOrderAbortable.prototype = Object.create(ParallelAbortable.prototype);
 PriorityOrderAbortable.prototype.constructor = PriorityOrderAbortable;