node_modules/@google-cloud/firestore/build/src/index.js
/**
     * Waits for the provided stream to become active and returns a paused but
     * healthy stream. If an error occurs before the first byte is read, the
     * method rejects the returned Promise.
     *
     * @private
     * @param backendStream The Node stream to monitor.
     * @param lifetime A Promise that resolves when the stream receives an 'end',
     * 'close' or 'finish' message.
     * @param requestTag A unique client-assigned identifier for this request.
     * @param request If specified, the request that should be written to the
     * stream after opening.
     * @returns A guaranteed healthy stream that should be used instead of
     * `backendStream`.
     */
Waits for the provided stream to become active and returns a paused but
healthy stream. If an error occurs before the first byte is read, the
method rejects the returned Promise.

@private
@param backendStream The Node stream to monitor.
Waits for the provided stream to become active and returns a paused but healthy stream . If an error occurs before the first byte is read the method rejects the returned Promise . @private @param backendStream The Node stream to monitor .
_initializeStream(backendStream, lifetime, requestTag, request) {
        const resultStream = new stream_1.PassThrough({ objectMode: true });
        resultStream.pause();
        let streamInitialized = false;
        return new Promise((resolve, reject) => {
            function streamReady() {
                if (!streamInitialized) {
                    streamInitialized = true;
                    logger_1.logger('Firestore._initializeStream', requestTag, 'Releasing stream');
                    resolve(resultStream);
                }
            }
            function streamEnded() {
                logger_1.logger('Firestore._initializeStream', requestTag, 'Received stream end');
                resultStream.unpipe(backendStream);
                resolve(resultStream);
                lifetime.resolve();
            }
            function streamFailed(err) {
                if (!streamInitialized) {
                    logger_1.logger('Firestore._initializeStream', requestTag, 'Received initial error:', err);
                    reject(err);
                }
                else {
                    logger_1.logger('Firestore._initializeStream', requestTag, 'Received stream error:', err);
                    setImmediate(() => {
                        resultStream.emit('error', err);
                    });
                }
            }
            backendStream.on('data', () => streamReady());
            backendStream.on('error', err => streamFailed(err));
            backendStream.on('end', () => streamEnded());
            backendStream.on('close', () => streamEnded());
            backendStream.on('finish', () => streamEnded());
            backendStream.pipe(resultStream);
            if (request) {
                logger_1.logger('Firestore._initializeStream', requestTag, 'Sending request: %j', request);
                backendStream.write(request, 'utf-8', err => {
                    if (err) {
                        streamFailed(err);
                    }
                    else {
                        logger_1.logger('Firestore._initializeStream', requestTag, 'Marking stream as healthy');
                        streamReady();
                    }
                });
            }
        });
    }
_initializeStream ( backendStream , lifetime , requestTag , request ) { const resultStream = new stream_1 . PassThrough ( { objectMode : true } ) ; resultStream . pause ( ) ; let streamInitialized = false ; return new Promise ( ( resolve , reject ) => { function streamReady ( ) { if ( ! streamInitialized ) { streamInitialized = true ; logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Releasing stream' ) ; resolve ( resultStream ) ; } } function streamEnded ( ) { logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Received stream end' ) ; resultStream . unpipe ( backendStream ) ; resolve ( resultStream ) ; lifetime . resolve ( ) ; } function streamFailed ( err ) { if ( ! streamInitialized ) { logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Received initial error:' , err ) ; reject ( err ) ; } else { logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Received stream error:' , err ) ; setImmediate ( ( ) => { resultStream . emit ( 'error' , err ) ; } ) ; } } backendStream . on ( 'data' , ( ) => streamReady ( ) ) ; backendStream . on ( 'error' , err => streamFailed ( err ) ) ; backendStream . on ( 'end' , ( ) => streamEnded ( ) ) ; backendStream . on ( 'close' , ( ) => streamEnded ( ) ) ; backendStream . on ( 'finish' , ( ) => streamEnded ( ) ) ; backendStream . pipe ( resultStream ) ; if ( request ) { logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Sending request: %j' , request ) ; backendStream . write ( request , 'utf-8' , err => { if ( err ) { streamFailed ( err ) ; } else { logger_1 . logger ( 'Firestore._initializeStream' , requestTag , 'Marking stream as healthy' ) ; streamReady ( ) ; } } ) ; } } ) ; }
Waits for the provided stream to become active and returns a paused but
 healthy stream.
Waits for the provided stream to become active and returns a paused but healthy stream .
/**
         * Whether we have resolved the Promise and returned the stream to the
         * caller.
         */ // If we receive an error before we were able to receive any data, // reject this stream. // We execute the forwarding of the 'error' event via setImmediate() as // V8 guarantees that the Promise chain returned from this method // is resolved before any code executed via setImmediate(). This // allows the caller to attach an error handler.