Skip to content

Commit

Permalink
Retrict the type of subscription iterables to AsyncIterable (#3131)
Browse files Browse the repository at this point in the history
# Summary

We want to return `Iterables` from here; it's not important that a generator itself is iterable.
  • Loading branch information
steveluscher authored Aug 21, 2024
1 parent 04942c9 commit 75710e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RpcWebSocketConnection } from '../websocket-connection';

const connection = null as unknown as RpcWebSocketConnection;

// [DESCRIBE] RpcWebSocketConnection
{
// It is an `AsyncIterable`
{
connection satisfies AsyncIterable<unknown>;
}

// It produces an `AsyncIterator`
{
connection[Symbol.asyncIterator]() satisfies AsyncIterator<unknown>;
}

// Is not an `AsyncIterableIterator`
{
// @ts-expect-error Should not be able to produce an iterable.
connection satisfies AsyncIterableIterator<unknown>;
// @ts-expect-error Should not be able to produce an iterable.
connection[Symbol.asyncIterator]() satisfies AsyncIterableIterator<unknown>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ type IteratorState =
onError: Parameters<ConstructorParameters<typeof Promise>[0]>[1];
onMessage: Parameters<ConstructorParameters<typeof Promise>[0]>[0];
};
export type RpcWebSocketConnection = Readonly<{
export interface RpcWebSocketConnection extends AsyncIterable<unknown> {
send(payload: unknown): Promise<void>;
[Symbol.asyncIterator](): AsyncGenerator<unknown>;
}>;
}

let EXPLICIT_ABORT_TOKEN: symbol;
function createExplicitAbortToken() {
Expand Down

0 comments on commit 75710e7

Please sign in to comment.