B2G/gecko/netwerk/test/httpserver/test/test_async_response_sending.js
/**
   * Initiates asynchronous waiting for data written to the copier's sink to be
   * available for reading from the input end of the sink's pipe.  The callback
   * stores the received data for comparison in the interceptor used in the
   * callback added by _waitForHelper and signals test completion when it
   * receives a zero-data-available notification (if the copier has notified
   * that it is finished; otherwise allows execution to continue until that has
   * occurred).
   */
Initiates asynchronous waiting for data written to the copier's sink to be
available for reading from the input end of the sink's pipe.  The callback
stores the received data for comparison in the interceptor used in the
callback added by _waitForHelper and signals test completion when it
receives a zero-data-available notification (if the copier has notified
that it is finished; otherwise allows execution to continue until that has
occurred).
Initiates asynchronous waiting for data written to the copier ' s sink to be available for reading from the input end of the sink ' s pipe . The callback stores the received data for comparison in the interceptor used in the callback added by _waitForHelper and signals test completion when it receives a zero - data - available notification ( if the copier has notified that it is finished ; otherwise allows execution to continue until that has occurred ) .
function _waitForWrittenData()
  {
    dumpn("*** _waitForWrittenData (" + this.name + ")");
    var self = this;
    var outputWrittenWatcher =
      {
        onInputStreamReady: function onInputStreamReady(input)
        {
          dumpn("*** outputWrittenWatcher.onInputStreamReady" +
                "(" + input.name + ")");
          if (self._allDataWritten)
          {
            do_throw("ruh-roh!  why are we getting notified of more data " +
                     "after we should have received all of it?");
          }
          self._waitingForData = false;
          try
          {
            var avail = input.available();
          }
          catch (e)
          {
            dumpn("*** available() threw!  error: " + e);
            if (self._completed)
            {
              dumpn("*** NB: this isn't a problem, because we've copied " +
                    "completely now, and this notify may have been expedited " +
                    "by maybeNotifyFinally such that we're being called when " +
                    "we can *guarantee* nothing is available any more");
            }
            avail = 0;
          }
          if (avail > 0)
          {
            var data = input.readByteArray(avail);
            do_check_eq(data.length, avail,
                        "readByteArray returned wrong number of bytes?");
            self._lastQuantum = data;
            self._receivedData.push.apply(self._receivedData, data);
          }
          if (avail === 0)
          {
            dumpn("*** all data received!");
            self._allDataWritten = true;
            if (self._copyingFinished)
            {
              dumpn("*** copying already finished, continuing to next test");
              self._testComplete();
            }
            else
            {
              dumpn("*** copying not finished, waiting for that to happen");
            }
            return;
          }
          self._waitForWrittenData();
        }
      };
    this._copiedDataStream.asyncWait(outputWrittenWatcher, 0, 1,
                                 gThreadManager.currentThread);
    this._waitingForData = true;
  }
function _waitForWrittenData ( ) { dumpn ( "*** _waitForWrittenData (" + this . name + ")" ) ; var self = this ; var outputWrittenWatcher = { onInputStreamReady : function onInputStreamReady ( input ) { dumpn ( "*** outputWrittenWatcher.onInputStreamReady" + "(" + input . name + ")" ) ; if ( self . _allDataWritten ) { do_throw ( "ruh-roh!  why are we getting notified of more data " + "after we should have received all of it?" ) ; } self . _waitingForData = false ; try { var avail = input . available ( ) ; } catch ( e ) { dumpn ( "*** available() threw!  error: " + e ) ; if ( self . _completed ) { dumpn ( "*** NB: this isn't a problem, because we've copied " + "completely now, and this notify may have been expedited " + "by maybeNotifyFinally such that we're being called when " + "we can *guarantee* nothing is available any more" ) ; } avail = 0 ; } if ( avail > 0 ) { var data = input . readByteArray ( avail ) ; do_check_eq ( data . length , avail , "readByteArray returned wrong number of bytes?" ) ; self . _lastQuantum = data ; self . _receivedData . push . apply ( self . _receivedData , data ) ; } if ( avail === 0 ) { dumpn ( "*** all data received!" ) ; self . _allDataWritten = true ; if ( self . _copyingFinished ) { dumpn ( "*** copying already finished, continuing to next test" ) ; self . _testComplete ( ) ; } else { dumpn ( "*** copying not finished, waiting for that to happen" ) ; } return ; } self . _waitForWrittenData ( ) ; } } ; this . _copiedDataStream . asyncWait ( outputWrittenWatcher , 0 , 1 , gThreadManager . currentThread ) ; this . _waitingForData = true ; }
Initiates asynchronous waiting for data written to the copier's sink to be
 available for reading from the input end of the sink's pipe.
Initiates asynchronous waiting for data written to the copier ' s sink to be available for reading from the input end of the sink ' s pipe .