/// import * as grpc from '@grpc/grpc-js'; import type { EventEmitter } from 'events'; import type { RequestContext } from './requestcontext'; /** * A call that can be canceled, as every grpc-js stream can. * * @internal */ export interface CancelableCall { /** * Ends the call on the client, failing it with `CANCELLED` if it is still * open. */ cancel(): void; } /** * The streams a cluster has open, so that closing it can cancel them before * the channel closes. * * @internal */ export declare class OpenStreams { private readonly _calls; /** * How many streams are open. */ get size(): number; /** * Records `call` as open. */ add(call: CancelableCall): void; /** * Records `call` as finished. */ delete(call: CancelableCall): void; /** * Cancels every open stream. Each fails its reader with `CANCELLED`. */ cancelAll(): void; } /** * The optional parts of {@link retryStream}. * * @internal */ export interface RetryStreamOptions { /** * Where the stream is recorded while it is open. */ streams?: OpenStreams; /** * Waits between attempts. */ sleep?: (ms: number) => Promise; } /** * Yields a server streaming call's messages, one at a time and as they are * read, sending the call through `ctx`. `open` starts one attempt, given the * call options to pass to grpc-js. * * A failure before the first message is retried like a unary call. The first * message, an empty one included, latches the stream: retrying after it * would replay what the caller has already read, so a later failure ends the * stream instead. The deadline covers the whole stream. * * Nothing is sent until the first message is asked for. Returning early * cancels the call. * * @internal */ export declare function retryStream(ctx: RequestContext, open: (options: grpc.CallOptions) => grpc.ClientReadableStream, options?: RetryStreamOptions): AsyncGenerator; /** * Runs `fn`, rethrowing anything it throws on a later tick as an uncaught * exception, so that an `error` emitted with no listener, or a throwing * `end` listener, is never lost. * * @internal */ export declare function rethrowListenerErrors(fn: () => void): void; /** * Ends a streamed result's `emitter` with `err`, as a classic query or * search ends on a failure. * * @internal */ export declare function endWithError(emitter: EventEmitter, err: unknown): void;