Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support readonly arrays as event names #234

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[@cursorsdottsx](https://github.com/cursorsdottsx) in [#245](https://github.com/apollographql/graphql-subscriptions/pull/245)
- Replace `iterall` use with native `Symbol.asyncIterator`. <br/>
[@n1ru4l](https://github.com/n1ru4l) in [#232](https://github.com/apollographql/graphql-subscriptions/pull/232)
- Support `readonly` arrays of event names. <br/>
[@rh389](https://github.com/rh389) in [#234](https://github.com/apollographql/graphql-subscriptions/pull/234)

### 2.0.1 (not yet released)

Expand Down
6 changes: 3 additions & 3 deletions src/pubsub-async-iterable-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PubSubEngine } from './pubsub-engine';
* A queue of PubSubEngine events waiting for next() calls to be made, which returns the queued events
* for handling. This queue expands as PubSubEngine events arrive without next() calls occurring in-between.
*
* @property eventsArray @type {string[]}
* @property eventsArray @type {readonly string[]}
* An array of PubSubEngine event names that this PubSubAsyncIterator should watch.
*
* @property allSubscribed @type {Promise<number[]>}
Expand All @@ -36,12 +36,12 @@ export class PubSubAsyncIterableIterator<T> implements AsyncIterableIterator<T>

private pullQueue: ((value: IteratorResult<T>) => void)[];
private pushQueue: T[];
private eventsArray: string[];
private eventsArray: readonly string[];
private allSubscribed: Promise<number[]>;
private running: boolean;
private pubsub: PubSubEngine;

constructor(pubsub: PubSubEngine, eventNames: string | string[]) {
constructor(pubsub: PubSubEngine, eventNames: string | readonly string[]) {
this.pubsub = pubsub;
this.pullQueue = [];
this.pushQueue = [];
Expand Down
2 changes: 1 addition & 1 deletion src/pubsub-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export abstract class PubSubEngine {
public abstract publish(triggerName: string, payload: any): Promise<void>;
public abstract subscribe(triggerName: string, onMessage: Function, options: Object): Promise<number>;
public abstract unsubscribe(subId: number);
public asyncIterableIterator<T>(triggers: string | string[]): PubSubAsyncIterableIterator<T> {
public asyncIterableIterator<T>(triggers: string | readonly string[]): PubSubAsyncIterableIterator<T> {
return new PubSubAsyncIterableIterator<T>(this, triggers);
}
}
2 changes: 1 addition & 1 deletion src/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('AsyncIterator', () => {
it('register to multiple events', done => {
const eventName = 'test2';
const ps = new PubSub();
const iterator = ps.asyncIterableIterator(['test', 'test2']);
const iterator = ps.asyncIterator(['test', 'test2'] as const);
const spy = sinon.spy();

iterator.next().then(() => {
Expand Down