UNPKG

2 kBTypeScriptView Raw
1/// <reference types="node" />
2import EventEmitter from 'events';
3/**
4 * @internal
5 */
6type PromisifyFunc<T> = (emitter: StreamablePromise<T>, resolve: (result: T) => void, reject: (err: Error) => void) => void;
7/**
8 * @internal
9 */
10export declare class StreamablePromise<T> extends EventEmitter implements Promise<T> {
11 private _promise;
12 private _promiseifyFn;
13 /**
14 * @internal
15 */
16 constructor(promisefyFn: PromisifyFunc<T>);
17 private get promise();
18 then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
19 catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
20 finally(onfinally?: (() => void) | undefined | null): Promise<T>;
21 /**
22 * @internal
23 */
24 get [Symbol.toStringTag](): string;
25}
26/**
27 * Provides the ability to be used as both a promise, or an event emitter. Enabling
28 * an application to easily retrieve all results using async/await, while also enabling
29 * streaming of results by listening for the row and meta events.
30 */
31export declare class StreamableRowPromise<T, TRow, TMeta> extends StreamablePromise<T> {
32 constructor(fn: (rows: TRow[], meta: TMeta) => T);
33}
34/**
35 * Provides the ability to be used as both a promise, or an event emitter. Enabling
36 * an application to easily retrieve all results using async/await, while also enabling
37 * streaming of results by listening for the replica event.
38 */
39export declare class StreamableReplicasPromise<T, TRep> extends StreamablePromise<T> {
40 constructor(fn: (replicas: TRep[]) => T);
41}
42export declare class StreamableScanPromise<T, TRes> extends StreamablePromise<T> {
43 private _cancelRequested;
44 constructor(fn: (results: TRes[]) => T);
45 get cancelRequested(): boolean;
46 cancelStreaming(): void;
47}
48export {};