Reputation:
Is it possible to batch guard's watch
notifications?
For example, if a subfolder is moved, watch
emits an event for every file. What I actually want is one notification, not several, if something changes.
Upvotes: 5
Views: 223
Reputation: 421
Although this doesn't batch changes and therefore doesn't have all the benefits of doing so, if all you need to do is prevent multiple builds after several files are saved at once, you can use a debounce mechanism such as the following:
LAST_REBUILD = Time.now
DEBOUNCE = 2 #seconds
guard :shell do
watch(%r{PATTERN}) do |m|
since_last = Time.now - LAST_REBUILD
if since_last > DEBOUNCE
n 'Rebuilding'
if system('LONG_RUNNING_PROCESS')
n 'Build complete'
LAST_REBUILD = Time.now
end
else
n "Skipping rebuild after only #{since_last} seconds"
end
end
Upvotes: 1