Method: FileMonitor#spawn

Defined in:
lib/FileMonitor.rb

#spawn(interval = 1) ⇒ Object Also known as: start

Spauns a child process that is looking for changes at every given interval.

The interval is in seconds and defaults to 1 second.

Example:

fm = FileMonitor.new {|watched_item| puts 'do something when file is changed'}
fm << @app_root + '/lib'
fm.spawn        # and now its doing its job...


204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/FileMonitor.rb', line 204

def spawn(interval = 1)
  if @pid.nil? 
    @pid = fork {monitor interval}
    Process.detach(pid)
    
    Kernel.at_exit do
      # sends the kill command unless the pid is not found on the system
      Process.kill('HUP', @pid) if process_running?
      @pid = nil
    end
  end
  @pid
end