*add cancel support to streaming query

*handle connectModule return properly
This commit is contained in:
Derrick Hammer 2022-08-31 20:10:24 -04:00
parent cfceda9bf1
commit 951a6f9554
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 13 additions and 4 deletions

View File

@ -240,6 +240,7 @@ export class SimpleRpcQuery extends RpcQueryBase {
export class StreamingRpcQuery extends SimpleRpcQuery {
protected _options: StreamingRpcQueryOptions;
private _sendUpdate?: DataFn;
constructor(
network: RpcNetwork,
@ -252,9 +253,15 @@ export class StreamingRpcQuery extends SimpleRpcQuery {
this._queryType = "streamingQuery";
}
public cancel() {
if (this._sendUpdate) {
this._sendUpdate({ cancel: true });
}
}
public run(): this {
this._promise = this._network.processQueue().then(() =>
connectModule(
this._promise = this._network.processQueue().then(() => {
const ret = connectModule(
RPC_MODULE,
this._queryType,
{
@ -264,8 +271,10 @@ export class StreamingRpcQuery extends SimpleRpcQuery {
network: this._network.networkId,
},
this._options.streamHandler
)
);
);
this._sendUpdate = ret[0];
return ret[1];
});
return this;
}