*Update dist

This commit is contained in:
Derrick Hammer 2022-08-31 19:59:06 -04:00
parent dafe044e00
commit 327c429d1e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 18 additions and 4 deletions

View File

@ -6,12 +6,14 @@ import RpcNetwork from "../network.js";
import { StreamingRpcQueryOptions } from "../types.js"; import { StreamingRpcQueryOptions } from "../types.js";
export default class StreamingRpcQuery extends SimpleRpcQuery { export default class StreamingRpcQuery extends SimpleRpcQuery {
protected _options: StreamingRpcQueryOptions; protected _options: StreamingRpcQueryOptions;
protected _canceled: boolean;
constructor( constructor(
network: RpcNetwork, network: RpcNetwork,
relay: string | Buffer, relay: string | Buffer,
query: RPCRequest, query: RPCRequest,
options: StreamingRpcQueryOptions options: StreamingRpcQueryOptions
); );
cancel(): void;
protected queryRelay(relay: string | Buffer): Promise<any>; protected queryRelay(relay: string | Buffer): Promise<any>;
} }
//# sourceMappingURL=streaming.d.ts.map //# sourceMappingURL=streaming.d.ts.map

View File

@ -1 +1 @@
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/query/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,cAAc,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,sBAAsB,CAAC;AACpE,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,cAAc;IAC3D,SAAS,CAAC,QAAQ,EAAE,wBAAwB,CAAC;gBAE3C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,wBAAwB;cAKnB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAwDjE"} {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/query/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,cAAc,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,sBAAsB,CAAC;AACpE,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,cAAc;IAC3D,SAAS,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IAC7C,SAAS,CAAC,SAAS,UAAS;gBAE1B,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,wBAAwB;IAM5B,MAAM;cAIG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAoEjE"}

View File

@ -5,10 +5,14 @@ import { clearTimeout, setTimeout } from "timers";
import { pack, unpack } from "msgpackr"; import { pack, unpack } from "msgpackr";
export default class StreamingRpcQuery extends SimpleRpcQuery { export default class StreamingRpcQuery extends SimpleRpcQuery {
_options; _options;
_canceled = false;
constructor(network, relay, query, options) { constructor(network, relay, query, options) {
super(network, relay, query, options); super(network, relay, query, options);
this._options = options; this._options = options;
} }
cancel() {
this._canceled = true;
}
async queryRelay(relay) { async queryRelay(relay) {
let socket; let socket;
let relayKey = relay; let relayKey = relay;
@ -30,20 +34,28 @@ export default class StreamingRpcQuery extends SimpleRpcQuery {
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let timer; let timer;
const finish = () => {
relay = relay;
this._responses[relay] = {};
resolve(null);
socket.end();
};
socket.on("data", (res) => { socket.on("data", (res) => {
relay = relay; relay = relay;
if (timer && timer.close) { if (timer && timer.close) {
clearTimeout(timer); clearTimeout(timer);
} }
if (this._canceled) {
finish();
return;
}
const response = unpack(res); const response = unpack(res);
if (response && response.error) { if (response && response.error) {
this._errors[relay] = response.error; this._errors[relay] = response.error;
return reject(null); return reject(null);
} }
if (response?.data.done) { if (response?.data.done) {
this._responses[relay] = {}; finish();
resolve(null);
socket.end();
return; return;
} }
this._options.streamHandler(response?.data.data); this._options.streamHandler(response?.data.data);