Sha256: 4df358ddaa4a6394d65ae4a738b2812bc6a9cdb47ac1645abc89e419d76f21a6

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module UV
  module Handle
    include Assertions, Resource, Listener

    def initialize(loop, pointer)
      @loop, @pointer = loop, pointer
    end

    # Public: Increment internal ref counter for the handle on the loop. Useful for
    # extending the loop with custom watchers that need to make loop not stop
    # 
    # Returns self
    def ref
      UV.ref(@pointer)

      self
    end

    # Public: Decrement internal ref counter for the handle on the loop, useful to stop
    # loop even when there are outstanding open handles
    # 
    # Returns self
    def unref
      UV.unref(@pointer)

      self
    end

    def close(&block)
      if not block.nil?
        assert_block(block)
        assert_arity(0, block)

        @close_block = block
      end

      UV.close(@pointer, callback(:on_close))

      self
    end

    def active?
      UV.is_active(@pointer) > 0
    end

    def closing?
      UV.is_closing(@pointer) > 0
    end

    protected

    def loop; @loop; end
    def handle; @pointer; end

    private

    def handle_name
      self.class.name.split('::').last.downcase.to_sym
    end

    def on_close(pointer)
      UV.free(pointer)
      clear_callbacks
      
      @close_block.call unless @close_block.nil?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
uvrb-0.1.4 lib/uv/handle.rb
uvrb-0.1.3 lib/uv/handle.rb
uvrb-0.1.2 lib/uv/handle.rb
uvrb-0.1.1 lib/uv/handle.rb