UNPKG

1.98 kBTypeScriptView Raw
1import { PubSubEngine } from 'graphql-subscriptions/dist/pubsub-engine';
2/**
3 * A class for digesting PubSubEngine events via the new AsyncIterator interface.
4 * This implementation is a generic version of the one located at
5 * https://github.com/apollographql/graphql-subscriptions/blob/master/src/event-emitter-to-async-iterator.ts
6 * @class
7 *
8 * @constructor
9 *
10 * @property pullQueue @type {Function[]}
11 * A queue of resolve functions waiting for an incoming event which has not yet arrived.
12 * This queue expands as next() calls are made without PubSubEngine events occurring in between.
13 *
14 * @property pushQueue @type {any[]}
15 * A queue of PubSubEngine events waiting for next() calls to be made.
16 * This queue expands as PubSubEngine events arrice without next() calls occurring in between.
17 *
18 * @property eventsArray @type {string[]}
19 * An array of PubSubEngine event names which this PubSubAsyncIterator should watch.
20 *
21 * @property allSubscribed @type {Promise<number[]>}
22 * A promise of a list of all subscription ids to the passed PubSubEngine.
23 *
24 * @property listening @type {boolean}
25 * Whether or not the PubSubAsynIterator is in listening mode (responding to incoming PubSubEngine events and next() calls).
26 * Listening begins as true and turns to false once the return method is called.
27 *
28 * @property pubsub @type {PubSubEngine}
29 * The PubSubEngine whose events will be observed.
30 */
31export declare class PubSubAsyncIterator<T> implements AsyncIterator<T> {
32 private pullQueue;
33 private pushQueue;
34 private eventsArray;
35 private allSubscribed;
36 private listening;
37 private pubsub;
38 constructor(pubsub: PubSubEngine, eventNames: string | string[]);
39 next(): Promise<IteratorResult<any, any>>;
40 return(): Promise<{
41 value: any;
42 done: boolean;
43 }>;
44 throw(error: any): Promise<never>;
45 private pushValue;
46 private pullValue;
47 private emptyQueue;
48 private subscribeAll;
49 private unsubscribeAll;
50}