Skip to content

Commit

Permalink
ts-sdk: expose alive attr
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 committed Nov 28, 2024
1 parent 63f4dc5 commit 41746cd
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sdk/typescript/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ export class Node {
resolve(): void;
reject(error: any): void;
}>();
private alive = false;
private _alive = false;
get alive() {
return this._alive;
}
private endpoints = new Map<EndpointAddr, Endpoint>;
private tempMailbox = new Map<EndpointAddr, Array<Message>>;
public textDecoder = new TextDecoder();

/**
* Create a new Node by connecting to the given URL
* @param options options for the connection
Expand Down Expand Up @@ -74,13 +77,13 @@ export class Node {
}
}
socket.onopen = (_evt) => {
node.alive = true;
node._alive = true;
node.openingWaitingPool.forEach((channel) => {
channel.resolve();
})
}
socket.onclose = (_evt) => {
node.alive = false;
node._alive = false;
}
return node;
}
Expand Down Expand Up @@ -111,7 +114,7 @@ export class Node {
}
private waitSocketOpen() {
return new Promise<void>((resolve, reject) => {
if (this.alive) {
if (this._alive) {
resolve();
} else {
this.openingWaitingPool.add({
Expand Down Expand Up @@ -169,7 +172,7 @@ export class Node {
return endpoint
}
public async destroyEndpoint(endpoint: Endpoint): Promise<void> {
if (!this.alive) {
if (!this._alive) {
return;
}
endpoint.closeMessageChannel();
Expand Down Expand Up @@ -199,7 +202,7 @@ export class Node {
this.endpoints.delete(endpoint.address);
}
public async updateInterests(endpoint: Endpoint, interests: Interest[]): Promise<void> {
if (!this.alive) {
if (!this._alive) {
return;
}
const requestId = this.nextRequestId();
Expand Down Expand Up @@ -287,7 +290,7 @@ export class Node {
}
}
public isAlive(): boolean {
return this.alive;
return this._alive;
}
public async close() {
await Promise.all(Array.from(this.endpoints.values()).map((endpoint) => {
Expand Down

0 comments on commit 41746cd

Please sign in to comment.