From f4e1dad0f71a7772014f03fc5650253b213469ca Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 31 Aug 2022 21:15:12 -0400 Subject: [PATCH] *Wrap sendUpdate in a function to ensure the request has not been canceled since the low level streamx appears to buffer --- src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 8c024d3..900fcd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,12 +166,18 @@ async function handleStreamingQuery(aq: ActiveQuery) { let resp: RPCResponse | null = null; + let canceled = false; + try { const rpcQuery = network.streamingQuery( relay as Buffer | string, query.method, query.module, - aq.sendUpdate, + (data) => { + if (!canceled) { + aq.sendUpdate?.(data); + } + }, query.data, { ...options } ); @@ -179,6 +185,7 @@ async function handleStreamingQuery(aq: ActiveQuery) { aq.setReceiveUpdate?.((message: any) => { if (message && message.cancel) { rpcQuery.cancel(); + canceled = true; } });