Skip to content

Commit 4ddcf74

Browse files
docs: document when to implement task stop method
1 parent dcdc3a4 commit 4ddcf74

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

docs/extending-tool-kit.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ class Rollup extends Task {
121121
module.exports = Rollup
122122
```
123123

124+
> [!NOTE]
125+
> If you're writing a task that runs something as an ongoing process, such as a server or a watch-mode build, you should also implement the `Task#stop` method to allow it to be stopped on error [when running tasks in parallel](../plugins/parallel), e.g.:
126+
> ```js
127+
> class Rollup extends Task {
128+
> async run() {
129+
> // ...
130+
> if(this.options.watch) {
131+
> this.watcher = rollup.watch(options)
132+
> // ...
133+
> } else {
134+
> // ...
135+
> }
136+
> }
137+
>
138+
> stop() {
139+
> this.watcher?.close()
140+
> }
141+
> }
142+
> ```
143+
124144
Then, in the plugin's `.toolkitrc.yml`, you can provide the default commands this task will run on. It's preferable to do this in the plugin `.toolkitrc.yml` instead of your top-level `.toolkitrc.yml` so your plugin is self-contained and can be more easily moved into its own repo or Tool Kit itself, if it's something that can be shared between multiple repos/teams.
125145

126146
```yml

0 commit comments

Comments
 (0)