Skip to content

Commit

Permalink
fix(server): Async iterator must implement return
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Mar 29, 2021
1 parent bdc32b2 commit d99982b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server.ts
Expand Up @@ -693,7 +693,8 @@ export function makeServer<E = unknown>(options: ServerOptions<E>): Server<E> {
/** multiple emitted results */
if (!(id in ctx.subscriptions)) {
// subscription was completed/canceled before the operation settled
operationResult.return?.();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
operationResult.return!(); // iterator must implement the return method
} else {
ctx.subscriptions[id] = operationResult;
for await (const result of operationResult) {
Expand All @@ -715,7 +716,8 @@ export function makeServer<E = unknown>(options: ServerOptions<E>): Server<E> {
return;
}
case MessageType.Complete: {
await ctx.subscriptions[message.id]?.return?.();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await ctx.subscriptions[message.id]?.return!(); // iterator must implement the return method
delete ctx.subscriptions[message.id]; // deleting the subscription means no further activity should take place
return;
}
Expand All @@ -730,7 +732,8 @@ export function makeServer<E = unknown>(options: ServerOptions<E>): Server<E> {
return async (code, reason) => {
if (connectionInitWait) clearTimeout(connectionInitWait);
for (const sub of Object.values(ctx.subscriptions)) {
await sub?.return?.();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await sub?.return!(); // iterator must implement the return method
}
if (ctx.acknowledged) await onDisconnect?.(ctx, code, reason);
await onClose?.(ctx, code, reason);
Expand Down

0 comments on commit d99982b

Please sign in to comment.