*add cancel support to streaming query
*handle connectModule return properly
This commit is contained in:
parent
cfceda9bf1
commit
951a6f9554
17
src/index.ts
17
src/index.ts
|
@ -240,6 +240,7 @@ export class SimpleRpcQuery extends RpcQueryBase {
|
||||||
|
|
||||||
export class StreamingRpcQuery extends SimpleRpcQuery {
|
export class StreamingRpcQuery extends SimpleRpcQuery {
|
||||||
protected _options: StreamingRpcQueryOptions;
|
protected _options: StreamingRpcQueryOptions;
|
||||||
|
private _sendUpdate?: DataFn;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
network: RpcNetwork,
|
network: RpcNetwork,
|
||||||
|
@ -252,9 +253,15 @@ export class StreamingRpcQuery extends SimpleRpcQuery {
|
||||||
this._queryType = "streamingQuery";
|
this._queryType = "streamingQuery";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public cancel() {
|
||||||
|
if (this._sendUpdate) {
|
||||||
|
this._sendUpdate({ cancel: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public run(): this {
|
public run(): this {
|
||||||
this._promise = this._network.processQueue().then(() =>
|
this._promise = this._network.processQueue().then(() => {
|
||||||
connectModule(
|
const ret = connectModule(
|
||||||
RPC_MODULE,
|
RPC_MODULE,
|
||||||
this._queryType,
|
this._queryType,
|
||||||
{
|
{
|
||||||
|
@ -264,8 +271,10 @@ export class StreamingRpcQuery extends SimpleRpcQuery {
|
||||||
network: this._network.networkId,
|
network: this._network.networkId,
|
||||||
},
|
},
|
||||||
this._options.streamHandler
|
this._options.streamHandler
|
||||||
)
|
);
|
||||||
);
|
this._sendUpdate = ret[0];
|
||||||
|
return ret[1];
|
||||||
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue