-
Notifications
You must be signed in to change notification settings - Fork 147
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
Easy way to handle cleanup on user initiated premature termination #463
Comments
Excellent idea. I'd love to hear other's thoughts on it. |
I think the right API might be to change export interface GluegunCommand<TContext extends Toolbox = Toolbox> {
/** The name of your command */
name?: string
/** A tweet-sized summary of your command */
description?: string
/** The function for running your command, can be async */
- run: (toolbox: TContext) => void
+ run: (toolbox: TContext, abortToken: AbortToken) => void
/** Should your command be shown in the listings */
hidden?: boolean
/** The command path, an array that describes how to get to this command */
commandPath?: string[]
/** Potential other names for this command */
alias?: string | string[] Where class AbortToken extends EventEmitter {
constructor() {
super();
}
} And run and/or runtime handles wiring up the approriate events. const token = new AbortToken();
process.on('SIGINT', () => {
token.emit('abort');
});
//...
if (command.run) {
await command.run(toolbox, token);
} with a command being able to do: run: (toolbox, abortToken) => {
const otherProcess = exec('do this thing', () => { /* do stuff */ });
abortToken.on('abort', () => otherProcess.kill());
} |
I'm not super keen on changing the Something like: run: (toolbox) => {
const otherProcess = exec('do this thing', () => { /* do stuff */ });
toolbox.meta.onAbort(() => otherProcess.kill())
} |
# [5.1.0](v5.0.0...v5.1.0) (2022-02-04) ### Features * **meta:** Adds onAbort callback to toolbox.meta ([#752](#752) by [@ugur-eren](https://github.com/ugur-eren)) ([7e6c21b](7e6c21b)), closes [#463](#463)
🎉 This issue has been resolved in version 5.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm not sure of the API shape of this, but it would be nice for gluegun to expose a way either through the toolbox (like https://developer.mozilla.org/en-US/docs/Web/API/AbortController) or in the command definition to have a "cleanup" command that would be run on
SIGINT
or other user initiated polite terminations. Basically to allow any quick cleanup that might be necessary.The text was updated successfully, but these errors were encountered: