Last active
December 16, 2015 04:19
-
-
Save tjsingleton/5376617 to your computer and use it in GitHub Desktop.
watch a dir for new files and do some work
This file contains 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
require 'listen' | |
require 'rb-fsevent' | |
LISTEN_PATH = '/tmp/m' | |
consumer, producer = IO.pipe | |
Dir["#{LISTEN_PATH}/*"].each {|n| producer.puts n } | |
2.times do | |
fork do | |
puts "consumer started #{$$}" | |
loop do | |
if IO.select([consumer], nil, nil, 2) | |
path = consumer.gets | |
puts "out[#{$$}]: #{path}" | |
end | |
end | |
end | |
end | |
Listen.to(LISTEN_PATH) do |_, added, _| | |
added.each{|n| producer.puts n } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment