B2G/gecko/toolkit/mozapps/extensions/test/browser/head.js
/**
   * Delay calling a callback to fake a time-consuming async operation.
   * The delay is specified by the apiDelay property, in milliseconds.
   * Parameters to send to the callback should be specified as arguments after
   * the aCallback argument.
   *
   * @param aCallback Callback to eventually call
   */
Delay calling a callback to fake a time-consuming async operation.
The delay is specified by the apiDelay property, in milliseconds.
Parameters to send to the callback should be specified as arguments after
the aCallback argument.

@param aCallback Callback to eventually call
Delay calling a callback to fake a time - consuming async operation . The delay is specified by the apiDelay property in milliseconds . Parameters to send to the callback should be specified as arguments after the aCallback argument . @param aCallback Callback to eventually call
function MP_delayCallback(aCallback, ...aArgs) {
    if (!this.useAsyncCallbacks) {
      aCallback.apply(null, params);
      return;
    }
    var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    var pos = this.callbackTimers.length;
    this.callbackTimers.push(timer);
    var self = this;
    timer.initWithCallback(function() {
      self.callbackTimers.splice(pos, 1);
      aCallback.apply(null, aArgs);
    }, this.apiDelay, timer.TYPE_ONE_SHOT);
  }
function MP_delayCallback ( aCallback , ... aArgs ) { if ( ! this . useAsyncCallbacks ) { aCallback . apply ( null , params ) ; return ; } var timer = Cc [ "@mozilla.org/timer;1" ] . createInstance ( Ci . nsITimer ) ; var pos = this . callbackTimers . length ; this . callbackTimers . push ( timer ) ; var self = this ; timer . initWithCallback ( function ( ) { self . callbackTimers . splice ( pos , 1 ) ; aCallback . apply ( null , aArgs ) ; } , this . apiDelay , timer . TYPE_ONE_SHOT ) ; }
Delay calling a callback to fake a time-consuming async operation.
Delay calling a callback to fake a time - consuming async operation .
// Need to keep a reference to the timer, so it doesn't get GC'ed