Skip to content

Instantly share code, notes, and snippets.

@unakatsuo
Created June 1, 2015 12:02
Show Gist options
  • Save unakatsuo/59195a045a49f73de188 to your computer and use it in GitHub Desktop.
Save unakatsuo/59195a045a49f73de188 to your computer and use it in GitHub Desktop.
Celluloid::IO & rb-inotify
require "celluloid/io"
require "rb-inotify"
require "forwardable"
module Celluloid
module IO
class INotify
extend Forwardable
def_delegators :@notifier, :watch, :close
def initialize
@notifier = ::INotify::Notifier.new
end
def wait_readable; Celluloid::IO.wait_readable(self); end
def to_io; @notifier.to_io; end
def process
wait_readable
@notifier.process
end
end
end
end
class A
include Celluloid::IO
def initialize()
@notifier = INotify.new
@notifier.watch("/tmp/a", :all_events) { |e|
puts "#{e} from /tmp/a"
}
end
def test
@notifier.process
end
end
A.new.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment