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:



41
42
43
# File 'lib/libuv/reactor.rb', line 41

def create(pointer)
    allocate.tap { |i| i.send(:initialize, FFI::AutoPointer.new(pointer, ::Libuv::Ext.method(:loop_delete))) }
end

#current::Libuv::Reactor | nil

Checks for the existence of a reactor on the current thread

Returns:



48
49
50
# File 'lib/libuv/reactor.rb', line 48

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

#default::Libuv::Reactor

Get default reactor

Returns:



18
19
20
21
22
23
# File 'lib/libuv/reactor.rb', line 18

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:



28
29
30
31
32
33
34
35
36
# File 'lib/libuv/reactor.rb', line 28

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