Sha256: e947510be2cd5f46c8662a5c0b771130b3eb86e34bd359f8049820f33087fc85

Contents?: true

Size: 881 Bytes

Versions: 12

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

module Libuv
    class FSEvent < Handle


        define_callback function: :on_fs_event, params: [:pointer, :string, :int, :int]


        EVENTS = {1 => :rename, 2 => :change}.freeze


        def initialize(reactor, path)
            @reactor = reactor

            fs_event_ptr = ::Libuv::Ext.allocate_handle_fs_event
            error = check_result ::Libuv::Ext.fs_event_init(reactor.handle, fs_event_ptr, path, callback(:on_fs_event, fs_event_ptr.address), 0)

            super(fs_event_ptr, error)
        end


        private


        def on_fs_event(handle, filename, events, status)
            e = check_result(status)

            if e
                reject(e)
            else
                # notify of a change
                ::Fiber.new { defer.notify(filename, EVENTS[events]) }.resume
            end
        end
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
libuv-3.1.9 lib/libuv/fs_event.rb
libuv-3.1.8 lib/libuv/fs_event.rb
libuv-3.1.7 lib/libuv/fs_event.rb
libuv-3.1.6 lib/libuv/fs_event.rb
libuv-3.1.5 lib/libuv/fs_event.rb
libuv-3.1.4 lib/libuv/fs_event.rb
libuv-3.1.3 lib/libuv/fs_event.rb
libuv-3.1.2 lib/libuv/fs_event.rb
libuv-3.1.1 lib/libuv/fs_event.rb
libuv-3.1.0 lib/libuv/fs_event.rb
libuv-3.0.1 lib/libuv/fs_event.rb
libuv-3.0.0 lib/libuv/fs_event.rb