fix: add _endPeerOnError optional function to conditionally end a peer if there is an error
This commit is contained in:
parent
dfe540d82c
commit
5971d0ace8
|
@ -7,11 +7,18 @@ import { uint8ArrayToHexString } from "binconv";
|
||||||
export default class RpcNetwork {
|
export default class RpcNetwork {
|
||||||
private _relaysAvailablePromise?: Promise<void>;
|
private _relaysAvailablePromise?: Promise<void>;
|
||||||
private _relaysAvailableResolve?: Function;
|
private _relaysAvailableResolve?: Function;
|
||||||
|
|
||||||
constructor(swarm = new Hyperswarm()) {
|
constructor(swarm = new Hyperswarm()) {
|
||||||
this._swarm = swarm;
|
this._swarm = swarm;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _endPeerOnError?: (peer: any) => Promise<boolean>;
|
||||||
|
|
||||||
|
set endPeerOnError(value: (peer: any) => Promise<boolean>) {
|
||||||
|
this._endPeerOnError = value;
|
||||||
|
}
|
||||||
|
|
||||||
private _methods: Map<string, Set<string>> = new Map<string, Set<string>>();
|
private _methods: Map<string, Set<string>> = new Map<string, Set<string>>();
|
||||||
|
|
||||||
get methods(): Map<string, Set<string>> {
|
get methods(): Map<string, Set<string>> {
|
||||||
|
@ -142,7 +149,9 @@ export default class RpcNetwork {
|
||||||
const resp = await query.result;
|
const resp = await query.result;
|
||||||
|
|
||||||
if (resp.error) {
|
if (resp.error) {
|
||||||
|
if (await this._endPeerOnError?.(relay)) {
|
||||||
relay.end();
|
relay.end();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue