*Add cancel support to streaming query via setReceiveUpdate

This commit is contained in:
Derrick Hammer 2022-08-31 20:03:11 -04:00
parent b094cb9274
commit 320b5c0a35
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 1 deletions

View File

@ -37,7 +37,7 @@ addHandler("addRelay", handleAddRelay);
addHandler("removeRelay", handleRemoveRelay); addHandler("removeRelay", handleRemoveRelay);
addHandler("clearRelays", handleClearRelays); addHandler("clearRelays", handleClearRelays);
addHandler("simpleQuery", handleSimpleQuery); addHandler("simpleQuery", handleSimpleQuery);
addHandler("streamingQuery", handleStreamingQuery); addHandler("streamingQuery", handleStreamingQuery, { receiveUpdates: true });
addHandler("wisdomQuery", handleWisdomQuery); addHandler("wisdomQuery", handleWisdomQuery);
addHandler("ready", handleReady); addHandler("ready", handleReady);
@ -175,6 +175,13 @@ async function handleStreamingQuery(aq: ActiveQuery) {
query.data, query.data,
{ ...options } { ...options }
); );
aq.setReceiveUpdate?.((message: any) => {
if (message && message.cancel) {
rpcQuery.cancel();
}
});
resp = await rpcQuery.result; resp = await rpcQuery.result;
} catch (e: any) { } catch (e: any) {
aq.reject(e); aq.reject(e);