From d99982b1fc887d913cb1b3a031b1c5c3706b4a35 Mon Sep 17 00:00:00 2001 From: Denis Badurina Date: Mon, 29 Mar 2021 10:25:35 +0200 Subject: [PATCH] fix(server): Async iterator must implement `return` Closes #149 --- src/server.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index 4f8c9f9a..251c2258 100644 --- a/src/server.ts +++ b/src/server.ts @@ -693,7 +693,8 @@ export function makeServer(options: ServerOptions): Server { /** 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) { @@ -715,7 +716,8 @@ export function makeServer(options: ServerOptions): Server { 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; } @@ -730,7 +732,8 @@ export function makeServer(options: ServerOptions): Server { 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);