/*!
* Copyright 2018 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
///
import { grpc } from 'google-gax';
import { PassThrough } from 'stream';
import { Subscriber } from './subscriber';
/**
* Error wrapper for gRPC status objects.
*
* @class
*
* @param {object} status The gRPC status object.
*/
export declare class StatusError extends Error implements grpc.ServiceError {
code: grpc.status;
details: string;
metadata: grpc.Metadata;
constructor(status: grpc.StatusObject);
}
/**
* Error thrown when we fail to open a channel for the message stream.
*
* @class
*
* @param {Error} err The original error.
*/
export declare class ChannelError extends Error implements grpc.ServiceError {
code: grpc.status;
details: string;
metadata: grpc.Metadata;
constructor(err: Error);
}
export interface MessageStreamOptions {
highWaterMark?: number;
maxStreams?: number;
timeout?: number;
}
/**
* @typedef {object} MessageStreamOptions
* @property {number} [highWaterMark=0] Configures the Buffer level for all
* underlying streams. See
* {@link https://nodejs.org/en/docs/guides/backpressuring-in-streams/} for
* more details.
* @property {number} [maxStreams=5] Number of streaming connections to make.
* @property {number} [timeout=300000] Timeout for establishing a connection.
*/
/**
* Streaming class used to manage multiple StreamingPull requests.
*
* @private
* @class
*
* @param {Subscriber} sub The parent subscriber.
* @param {MessageStreamOptions} [options] The message stream options.
*/
export declare class MessageStream extends PassThrough {
private _keepAliveHandle;
private _fillHandle?;
private _options;
private _retrier;
private _streams;
private _subscriber;
constructor(sub: Subscriber, options?: MessageStreamOptions);
/**
* Destroys the stream and any underlying streams.
*
* @param {error?} error An error to emit, if any.
* @private
*/
destroy(error?: Error | null): void;
/**
* Destroys the stream and any underlying streams.
*
* @param {error?} error An error to emit, if any.
* @param {Function} callback Callback for completion of any destruction.
* @private
*/
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
/**
* Adds a StreamingPull stream to the combined stream.
*
* @private
*
* @param {stream} stream The StreamingPull stream.
*/
private _addStream;
/**
* Attempts to create and cache the desired number of StreamingPull requests.
* gRPC does not supply a way to confirm that a stream is connected, so our
* best bet is to open the streams and use the client.waitForReady() method to
* confirm everything is ok.
*
* @private
*
* @returns {Promise}
*/
private _fillStreamPool;
/**
* It is critical that we keep as few `PullResponse` objects in memory as
* possible to reduce the number of potential redeliveries. Because of this we
* want to bypass gax for StreamingPull requests to avoid creating a Duplexify
* stream, doing so essentially doubles the size of our readable buffer.
*
* @private
*
* @returns {Promise.