Class: Libuv::Handle

Inherits:
Q::DeferredPromise show all
Includes:
Assertions, Listener, Resource
Defined in:
lib/libuv/handle.rb

Direct Known Subclasses

Async, Check, FSEvent, Idle, Pipe, Prepare, Signal, TCP, TTY, Timer, UDP

Constant Summary

Constants included from Assertions

Assertions::MSG_NO_PROC

Constants inherited from Q::Promise

Q::Promise::MAKE_PROMISE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertions

#assert_block, #assert_boolean, #assert_type

Methods included from Resource

#check_result, #check_result!, #resolve, #to_ptr

Methods inherited from Q::DeferredPromise

#resolved?, #then

Methods inherited from Q::Promise

#catch, #finally, #progress

Constructor Details

#initialize(pointer, error) ⇒ Handle

Returns a new instance of Handle.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/libuv/handle.rb', line 11

def initialize(pointer, error)
    @pointer = pointer

    # Initialise the promise
    super(loop, loop.defer)

    # clean up on init error (always raise here)
    if error
        ::Libuv::Ext.free(pointer)
        defer.reject(error)
        @closed = true
        raise error
    end
end

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



7
8
9
# File 'lib/libuv/handle.rb', line 7

def closed
  @closed
end

#loopObject (readonly)

Returns the value of attribute loop.



8
9
10
# File 'lib/libuv/handle.rb', line 8

def loop
  @loop
end

#storageObject

A place for general storage



6
7
8
# File 'lib/libuv/handle.rb', line 6

def storage
  @storage
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/libuv/handle.rb', line 50

def active?
    ::Libuv::Ext.is_active(handle) > 0
end

#closeObject



44
45
46
47
48
# File 'lib/libuv/handle.rb', line 44

def close
    return if @closed
    @closed = true
    Libuv::Ext.close(handle, callback(:on_close))
end

#closing?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/libuv/handle.rb', line 54

def closing?
    ::Libuv::Ext.is_closing(handle) > 0
end

#refObject

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



30
31
32
33
# File 'lib/libuv/handle.rb', line 30

def ref
    return if @closed
    ::Libuv::Ext.ref(handle)
end

#unrefObject

Public: Decrement internal ref counter for the handle on the loop, useful to stop loop even when there are outstanding open handles

Returns self



39
40
41
42
# File 'lib/libuv/handle.rb', line 39

def unref
    return if @closed
    ::Libuv::Ext.unref(handle)
end