Module: Libuv::Reactor::ClassMethods

Included in:
Libuv::Reactor
Defined in:
lib/libuv/reactor.rb

Instance Method Summary collapse

Instance Method Details

#create(pointer) ⇒ ::Libuv::Reactor

Build a Ruby Libuv reactor from an existing reactor pointer

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/libuv/reactor.rb', line 48

def create(pointer)
    reactor = allocate.tap { |i| i.send(:initialize, pointer) }
    if CRITICAL.owned?
        @reactors ||= []
        @reactors << reactor
    else
        CRITICAL.synchronize {
            @reactors ||= []
            @reactors << reactor
        }
    end
    reactor
end

#current::Libuv::Reactor | nil

Checks for the existence of a reactor on the current thread

Returns:



65
66
67
# File 'lib/libuv/reactor.rb', line 65

def current
    Thread.current.thread_variable_get(:reactor)
end

#default::Libuv::Reactor

Get default reactor

Returns:



25
26
27
28
29
30
# File 'lib/libuv/reactor.rb', line 25

def default
    return @default unless @default.nil?
    CRITICAL.synchronize {
        return @default ||= create(::Libuv::Ext.default_loop)
    }
end

#new(&blk) ⇒ ::Libuv::Reactor

Create new Libuv reactor

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/libuv/reactor.rb', line 35

def new(&blk)
    thread = create(::Libuv::Ext.loop_new)
    if block_given?
        ::Thread.new do
            thread.run &blk
        end
    end
    thread
end