轮询适配器在 Guard/listen 中如何工作?
How does the polling adapter work in Guard/listen?
Guard/listen includes a polling adapter. The README.md says, although it's much slower than other adapters, it works on every platform/system and scenario (including network filesystems such as VM shared folders). But how does it work? Does it scan the filesystem and store mtime values and self-notify if they change? (It's not clear from reading the source.)
(如果您回答,post Guard wiki 上的信息也很棒。)
它递归地连续扫描所有给定的目录。
:latency
参数告诉它在扫描之间休眠多长时间。
代码相当复杂,因为轮询与 OSX 适配器共享很多内容。
这是扫描目录的位置:https://github.com/guard/listen/blob/master/lib/listen/directory.rb
这是存储模式和 mtime 的结构:https://github.com/guard/listen/blob/master/lib/listen/record.rb
下面是部分文件系统快照是如何失效的:https://github.com/guard/listen/blob/master/lib/listen/change.rb#L31
一般来说,只有当要扫描的大目录太多时,轮询才会变慢。这就是为什么最好只监视选定的目录并避免包含你不想要的文件的大目录 edit/change,例如node_modules
或 vendor
之类的东西。 Listen 已忽略某些目录的规则。
调试模式(使用环境变量 LISTEN_GEM_DEBUGGING=2
设置)可以让您深入了解幕后发生的事情。
我其实可以更详细地回答,只是我认为现有的架构很差。
所以我宁愿重写它以使其更清晰和更易于维护。
Guard/listen includes a polling adapter. The README.md says, although it's much slower than other adapters, it works on every platform/system and scenario (including network filesystems such as VM shared folders). But how does it work? Does it scan the filesystem and store mtime values and self-notify if they change? (It's not clear from reading the source.)
(如果您回答,post Guard wiki 上的信息也很棒。)
它递归地连续扫描所有给定的目录。
:latency
参数告诉它在扫描之间休眠多长时间。
代码相当复杂,因为轮询与 OSX 适配器共享很多内容。
这是扫描目录的位置:https://github.com/guard/listen/blob/master/lib/listen/directory.rb
这是存储模式和 mtime 的结构:https://github.com/guard/listen/blob/master/lib/listen/record.rb
下面是部分文件系统快照是如何失效的:https://github.com/guard/listen/blob/master/lib/listen/change.rb#L31
一般来说,只有当要扫描的大目录太多时,轮询才会变慢。这就是为什么最好只监视选定的目录并避免包含你不想要的文件的大目录 edit/change,例如node_modules
或 vendor
之类的东西。 Listen 已忽略某些目录的规则。
调试模式(使用环境变量 LISTEN_GEM_DEBUGGING=2
设置)可以让您深入了解幕后发生的事情。
我其实可以更详细地回答,只是我认为现有的架构很差。
所以我宁愿重写它以使其更清晰和更易于维护。