fix: add _endPeerOnError optional function to conditionally end a peer if there is an error

This commit is contained in:
Derrick Hammer 2023-07-22 09:17:34 -04:00
parent dfe540d82c
commit 5971d0ace8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 1 deletions

View File

@ -7,11 +7,18 @@ import { uint8ArrayToHexString } from "binconv";
export default class RpcNetwork {
private _relaysAvailablePromise?: Promise<void>;
private _relaysAvailableResolve?: Function;
constructor(swarm = new Hyperswarm()) {
this._swarm = swarm;
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>>();
get methods(): Map<string, Set<string>> {
@ -142,7 +149,9 @@ export default class RpcNetwork {
const resp = await query.result;
if (resp.error) {
relay.end();
if (await this._endPeerOnError?.(relay)) {
relay.end();
}
return;
}