Some tasks utilize the watch to trigger an event, ie: live reload. With Grunt
v0.3, those tasks on first run would create a variable, ie servers
. Then
subsequently ran by the watch task would check if the variable exists and then
use it. Since the new watch spawns tasks, this is no longer possible.
- Tasks would only have to be ran once (less configuration)
- Could also solve the common request for a task to know which files have been modified
- Simple to implement
- Watch task isn't as generalized as tasks now rely directly on the watch task
A demo of this is here albeit not exactly what @cowboy proposed. When the watch runs the child, the child can inform the parent, ie: okay now reload.
- Operates very similiarly to previous functionality (requiring minimal changes from tasks authors)
- Keeps the watch generalized. Only relies on the watch to run the child task
- Relies on opening another port
- A bit complicated and could lead to unforseen issues
- Not that speedy on Windows
- Allows the watch task to run like Grunt@0.3 requiring 0 changes from plugin authors
- Could get a list of impacted files
- Tasks rely on a user setting a watch config to work
- Tasks fail in ways Grunt can't stop. One task failure can kill the entire watch
- Tasks step on each other as they are in the same context. For test runners this is bad.
First runs the parent
and the watch runs the child
. The child communicates
with the parent by writing to a file or database.
- Task only relies on the watch to run tasks
- A lot of configuration required
So tasks could know they've been spawned by the watch by checking, ie:
grunt.option('spawned-by-watch');
- Easy to implement
- Watch task isnt as generalized as tasks now rely on this being done by the watch
- Child task still doesn't have access to communicate with parent
Emit events and allow watch to be configured to run under the same context
Besides reload, what are some other use cases that require running a stateful process in the background, which is triggered by watch?
I couldn't think of any of the top of my head, and for reload there might a relatively simple solution (cf. manuel-woelker/grunt-reload@f438be5). So maybe this isn't a problem after all.