-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(core): allow restart logic to be triggered using an event #3380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. PTAL @caoxiemeihao
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still feels side-effecty/hacky. Like, we're still emitting a random string on a random emitter. This should just be a method exposed via forge core, or plugin base that can be called normally
What about: // at the top-level of the module
const restartAppEventEmitter = new EventEmitter()
// ...
if (interactive) {
restartAppEventEmitter.on('restart', async () => {
if (lastSpawned) {
console.info(chalk.cyan('\nRestarting App\n'));
lastSpawned.restarted = true;
lastSpawned.kill('SIGTERM');
lastSpawned.emit('restarted', await forgeSpawnWrapper());
}
});
process.stdin.on('data', async (data) => {
if (data.toString().trim() === 'rs') {
restartApp();
}
});
process.stdin.resume();
}
// ...
export function restartApp() {
restartAppEventEmitter.emit('restart');
} This would work without consumers directly emitting anything and still allows us to keep the logic simple. |
72410fd
to
c670573
Compare
Here's the alternative I mentioned in my previous comment: 3a3cf97. I believe using some form of event-based approach is the best option here — the restart logic depends on variables that are inside the scope of the enclosing |
6acb75a
to
3a3cf97
Compare
3a3cf97
to
ef1e465
Compare
Implemented in #3468 |
Summarize your changes:
This allows the restart event to be triggered from anywhere in Forge and should make it possible for @caoxiemeihao to address the
process.stdin.emit
issue mentioned in #3203 (comment):At first, I was thinking of creating a dedicated
EventEmitter
instance for this, butprocess
is an event emitter and is available everywhere, so that makes things simpler if a bit hacky.