B2G/gecko/netwerk/test/httpserver/test/test_async_response_sending.js
/**
   * Sets up a stream interceptor that will verify that each piece of data
   * written to the sink by the copier corresponds to the currently expected
   * pieces of data, calls the trigger, then waits for those pieces of data to
   * be received.  Once all have been received, the interceptor is removed and
   * the next task is asynchronously executed.
   *
   * @param name : string
   *   name of the task created by this, used in debugging output
   * @param dataQuantums : [[uint]]
   *   array of expected arrays of bytes to be written to the sink by the copier
   * @param trigger : function() : void
   *   function to call after setting up the interceptor to wait for
   *   notifications (which will be generated as a result of this function's
   *   actions)
   */
Sets up a stream interceptor that will verify that each piece of data
written to the sink by the copier corresponds to the currently expected
pieces of data, calls the trigger, then waits for those pieces of data to
be received.  Once all have been received, the interceptor is removed and
the next task is asynchronously executed.

@param name : string
name of the task created by this, used in debugging output
@param dataQuantums : [[uint]]
array of expected arrays of bytes to be written to the sink by the copier
@param trigger : function() : void
function to call after setting up the interceptor to wait for
notifications (which will be generated as a result of this function's
actions)
Sets up a stream interceptor that will verify that each piece of data written to the sink by the copier corresponds to the currently expected pieces of data calls the trigger then waits for those pieces of data to be received . Once all have been received the interceptor is removed and the next task is asynchronously executed . @param name : string name of the task created by this used in debugging output @param dataQuantums : [[ uint ]] array of expected arrays of bytes to be written to the sink by the copier @param trigger : function () : void function to call after setting up the interceptor to wait for notifications ( which will be generated as a result of this function ' s actions )
function _waitForHelper(name, dataQuantums, trigger)
  {
    var self = this;
    this._addToTasks(function waitForHelperTask()
    {
      note(name);
      var quantumIndex = 0;
      var streamReadyCallback =
        {
          onInputStreamReady: function wrapperOnInputStreamReady(input)
          {
            dumpn("*** streamReadyCallback.onInputStreamReady" +
                  "(" + input.name + ")");
            do_check_eq(this, streamReadyCallback, "sanity");
            try
            {
              if (quantumIndex < dataQuantums.length)
              {
                var quantum = dataQuantums[quantumIndex++];
                var sz = quantum.length;
                do_check_eq(self._lastQuantum.length, sz,
                            "different quantum lengths");
                for (var i = 0; i < sz; i++)
                {
                  do_check_eq(self._lastQuantum[i], quantum[i],
                              "bad data at " + i);
                }
                dumpn("*** waiting to check remaining " +
                      (dataQuantums.length - quantumIndex) + " quantums...");
              }
            }
            finally
            {
              if (quantumIndex === dataQuantums.length)
              {
                dumpn("*** data checks completed!  next task...");
                self._copiedDataStream.removeStreamReadyInterceptor();
                self._stageNextTask();
              }
            }
          }
        };
      var interceptor =
        createStreamReadyInterceptor(streamReadyCallback, "onInputStreamReady");
      self._copiedDataStream.interceptStreamReadyCallbacks(interceptor);
      trigger();
    });
  }
function _waitForHelper ( name , dataQuantums , trigger ) { var self = this ; this . _addToTasks ( function waitForHelperTask ( ) { note ( name ) ; var quantumIndex = 0 ; var streamReadyCallback = { onInputStreamReady : function wrapperOnInputStreamReady ( input ) { dumpn ( "*** streamReadyCallback.onInputStreamReady" + "(" + input . name + ")" ) ; do_check_eq ( this , streamReadyCallback , "sanity" ) ; try { if ( quantumIndex < dataQuantums . length ) { var quantum = dataQuantums [ quantumIndex ++ ] ; var sz = quantum . length ; do_check_eq ( self . _lastQuantum . length , sz , "different quantum lengths" ) ; for ( var i = 0 ; i < sz ; i ++ ) { do_check_eq ( self . _lastQuantum [ i ] , quantum [ i ] , "bad data at " + i ) ; } dumpn ( "*** waiting to check remaining " + ( dataQuantums . length - quantumIndex ) + " quantums..." ) ; } } finally { if ( quantumIndex === dataQuantums . length ) { dumpn ( "*** data checks completed!  next task..." ) ; self . _copiedDataStream . removeStreamReadyInterceptor ( ) ; self . _stageNextTask ( ) ; } } } } ; var interceptor = createStreamReadyInterceptor ( streamReadyCallback , "onInputStreamReady" ) ; self . _copiedDataStream . interceptStreamReadyCallbacks ( interceptor ) ; trigger ( ) ; } ) ; }
Sets up a stream interceptor that will verify that each piece of data
 written to the sink by the copier corresponds to the currently expected
 pieces of data, calls the trigger, then waits for those pieces of data to
 be received.
Sets up a stream interceptor that will verify that each piece of data written to the sink by the copier corresponds to the currently expected pieces of data calls the trigger then waits for those pieces of data to be received .
/*
       * Intercept all data-available notifications so we can continue when all
       * the ones we expect have been received.
       */ /* Do the deed. */