Skip to content

Commit

Permalink
Refactor broadcating message to threads
Browse files Browse the repository at this point in the history
PR-URL: #1920
  • Loading branch information
tshemsedinov committed Oct 10, 2023
1 parent 69367b5 commit b9da912
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const logError = (type) => (err) => {
if (impress.initialization) exit('Can not start Application server', 1);
};

const broadcast = (app, data) => {
for (const thread of app.threads.values()) {
thread.postMessage(data);
}
};

const startWorker = async (app, kind, port, id = ++impress.lastWorkerId) => {
const workerData = { id, kind, root: app.root, path: app.path, port };
const execArgv = [...process.execArgv, `--test-reporter=${REPORTER_PATH}`];
Expand Down Expand Up @@ -178,13 +184,6 @@ const loadApplications = async () => {
}
};

const stopApplication = (dir) => {
const app = impress.applications.get(dir);
for (const thread of app.threads.values()) {
thread.postMessage({ name: 'stop' });
}
};

const stop = async (code = 0) => {
const portsClosed = new Promise((resolve) => {
impress.console.info('Graceful shutdown in worker 0');
Expand All @@ -198,7 +197,7 @@ const stop = async (code = 0) => {
};
});
for (const app of impress.applications.values()) {
stopApplication(app.path);
broadcast(app, { name: 'stop' });
}
await portsClosed;
exit('Application server stopped', code);
Expand Down

0 comments on commit b9da912

Please sign in to comment.