Sha256: 09377e42c830a3ad40f2e521a109529a2c6818325ae04bbec68c831a2036207c

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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)
      assert_block(block)
      assert_arity(0, block)

      @close_block = block

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uvrb-0.1.0 lib/uv/handle.rb