Skip to content

Commit

Permalink
update ports
Browse files Browse the repository at this point in the history
  • Loading branch information
kstoykov committed Jul 12, 2022
1 parent e8fb8f4 commit 46d059c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
39 changes: 30 additions & 9 deletions tools/builder/helpers/ServerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ServerHelper {
this.status = ServerHelper.STATUS_STOPPED;
}

restart() {
async restart() {
if (this.status === ServerHelper.STATUS_STARTING || this.status === ServerHelper.STATUS_STOPPING) {
return;
}
Expand All @@ -19,14 +19,8 @@ class ServerHelper {
return;
}

this.server.send('SERVER_MSG::EXIT');
this.server.on('exit', () => {
this.status = ServerHelper.STATUS_STOPPED;
this.start();
});
this.server = null;

this.status = ServerHelper.STATUS_STOPPING;
await this.stop();
this.start();
}

start() {
Expand All @@ -52,6 +46,33 @@ class ServerHelper {
this.status = ServerHelper.STATUS_STARTING;
}

stop() {
return new Promise((resolve, reject) => {
const run = async () => {
if (this.status === ServerHelper.STATUS_STOPPED || this.status === ServerHelper.STATUS_STOPPING) {
resolve();
return;
}

while (this.status === ServerHelper.STATUS_STARTING) {
await new Promise((resolveInner, rejectInner) => { setTimeout(resolveInner, 100) });
}

if (this.status === ServerHelper.STATUS_STARTED) {
this.server.send('SERVER_MSG::EXIT');
this.server.on('exit', () => {
this.status = ServerHelper.STATUS_STOPPED;
resolve();
});
this.server = null;
this.status = ServerHelper.STATUS_STOPPING;
}
}

run();
});
}

onStdOut(data) {
console.log(data.toString().trim());
}
Expand Down
9 changes: 9 additions & 0 deletions tools/builder/targets/DevTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class DevTarget {

if (serverHelper !== null) {
serverHelper.start();

process.on('SIGINT', async () => {
await serverHelper.stop();
process.exit(0);
})
process.on('SIGTERM', async () => {
await serverHelper.stop();
process.exit(0);
})
}
}

Expand Down

0 comments on commit 46d059c

Please sign in to comment.