Skip to content
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

Introduce deinit hook #1263

Closed
Oscaner opened this issue Dec 14, 2024 · 2 comments · Fixed by #1276
Closed

Introduce deinit hook #1263

Oscaner opened this issue Dec 14, 2024 · 2 comments · Fixed by #1276

Comments

@Oscaner
Copy link

Oscaner commented Dec 14, 2024

Is your feature request related to a problem? Please describe.
I have a command to chain sub-commands, and I just want to run final postrun hook, but cannot.

Workflow:
-> [hook] init
-> [hook] prerun
-> [command] main
----> [hook] prerun
----> [command] sub1
----> [hook] postrun
----> [hook] prerun
----> [command] sub2
----> [hook] postrun
----> ...
-> [hook] postrun
-> [hook] deinit

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@mdonnalley
Copy link
Contributor

mdonnalley commented Dec 16, 2024

@Oscaner why do you need to use a hook?

If you have a command that's chaining other commands, couldn't you just execute your "deinit" code at the end? This is what I'm imagining

class MyCommand extends Command {
  run() {
   // run "command one"
    await this.config.runCommand('command:one')
   // run "command two"
    await this.config.runCommand('command:two')
   // final logic here
  }
}

@Oscaner
Copy link
Author

Oscaner commented Dec 23, 2024

@Oscaner why do you need to use a hook?

If you have a command that's chaining other commands, couldn't you just execute your "deinit" code at the end? This is what I'm imagining

class MyCommand extends Command {
  run() {
   // run "command one"
    await this.config.runCommand('command:one')
   // run "command two"
    await this.config.runCommand('command:two')
   // final logic here
  }
}

For example, I init the Puppeteer browser in "init" hook, and cached the Browser in LRU-cache to globally reuse in every commands.

I don't want remove the Browser in every commands (this is why I cannot use "postrun" hook),
but want remove the Browser when the Chain command finished, or when I just run the independent command (command:one), also want to remove the Browser.

So I need "deinit" hook, just run once when command finished, even if this command contains multiple commands or not.

For another example, put some temporary files in local, and remove them when chain command finished, or independent command finished.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants