Skip to content

Commit

Permalink
add close waiting pools for ts sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 committed Dec 16, 2024
1 parent aba2dd6 commit a56ad91
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions sdk/typescript/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ export class Node {
resolve(): void;
reject(error: any): void;
}>();
private closingWaitingPool = new Set<{
resolve(): void;
reject(error: any): void;
}>();
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 @@ -84,6 +88,9 @@ export class Node {
}
socket.onclose = (_evt) => {
node._alive = false;
node.closingWaitingPool.forEach((channel) => {
channel.resolve();
})
}
return node;
}
Expand Down Expand Up @@ -112,7 +119,7 @@ export class Node {
})
})
}
private waitSocketOpen() {
public waitSocketOpen() {
return new Promise<void>((resolve, reject) => {
if (this._alive) {
resolve();
Expand All @@ -124,6 +131,18 @@ export class Node {
}
})
}
public waitSocketClose() {
return new Promise<void>((resolve, reject) => {
if (!this._alive) {
resolve();
} else {
this.closingWaitingPool.add({
resolve,
reject
})
}
})
}
/**
* create a new endpoint
* @param topic topic code
Expand Down

0 comments on commit a56ad91

Please sign in to comment.