Created
September 13, 2010 23:59
-
-
Save hassox/578285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module EmGlobWatcher | |
| # Setup to watch a glob on the file system. | |
| # If the glob is detected, the path of the matching file will be yielded to the block | |
| # You may pass it an interval on how often to scan the directory. | |
| # The block will be executed before the next interval is set | |
| # @param glob - The file glob to watch for | |
| # @param interval - The interval in seconds to poll the file system | |
| def self.watch(glob, interval = 0.5, &blk) | |
| raise "EventMacine must be running" unless EM.reactor_running? | |
| watcher = nil | |
| watcher = lambda do | |
| Dir.glob(glob).each do |f| | |
| blk.call f | |
| end | |
| EM.add_timer(interval, watcher) | |
| end | |
| EM.add_timer(interval, watcher) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment