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 36172 cdb50d9fdd906047708d2a84b7c6268b6d765c47
parent 36171 c6392cfb16a0a321b5a4883494cb1fe3cac79408
child 36173 5477fcc25b929b4d74bc4cb60ed24cccd030bb0e
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
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;