From 320b5c0a35d9813808222d0aa3c81ca633bb9b8a Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 31 Aug 2022 20:03:11 -0400 Subject: [PATCH] *Add cancel support to streaming query via setReceiveUpdate --- src/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 968798e..8c024d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ addHandler("addRelay", handleAddRelay); addHandler("removeRelay", handleRemoveRelay); addHandler("clearRelays", handleClearRelays); addHandler("simpleQuery", handleSimpleQuery); -addHandler("streamingQuery", handleStreamingQuery); +addHandler("streamingQuery", handleStreamingQuery, { receiveUpdates: true }); addHandler("wisdomQuery", handleWisdomQuery); addHandler("ready", handleReady); @@ -175,6 +175,13 @@ async function handleStreamingQuery(aq: ActiveQuery) { query.data, { ...options } ); + + aq.setReceiveUpdate?.((message: any) => { + if (message && message.cancel) { + rpcQuery.cancel(); + } + }); + resp = await rpcQuery.result; } catch (e: any) { aq.reject(e);