Skip to content

Commit

Permalink
fix: can start multi times
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Aug 23, 2023
1 parent c32523b commit 76ba3c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class Server {
protected readonly logger: Console;
private readonly _serverImpl: GRPCServerImpl;
private readonly _server: GRPCServer;
#start = false;

constructor(port: string = process.env.appcallback_GRPC_PORT ?? '9999',
GRPCServerInstance?: any,
Expand All @@ -54,9 +55,10 @@ export default class Server {
}

async start(): Promise<void> {
if (this.#start) return;
this.#start = true;
await this._bind();
this._server.start();
await sleep(250);
}

async close(): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/server/GRPCServerImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ describe.skip('server/GRPCServerImpl.test.ts', () => {
const serverImpl = new CustomGRPCServerImpl(pubsubConfig);
server = new Server('9999', serverImpl);
await server.start();
// start multi times should work
await server.start();
});

afterAll(async () => {
Expand Down

0 comments on commit 76ba3c0

Please sign in to comment.