Created
June 1, 2015 12:02
-
-
Save unakatsuo/59195a045a49f73de188 to your computer and use it in GitHub Desktop.
Celluloid::IO & rb-inotify
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 "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