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:



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

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:



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

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

#default::Libuv::Reactor

Get default reactor

Returns:



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

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:



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

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