简体   繁体   English

Guard:批量监视通知

[英]Guard: batch watch notifications

Is it possible to batch guard's watch notifications? 是否可以批量监护 watch通知?

For example, if a subfolder is moved, watch emits an event for every file. 例如,如果移动子文件夹,则watch会为每个文件发出一个事件。 What I actually want is one notification, not several, if something changes. 我真正想要的是一个通知,而不是几个,如果有什么变化。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM