Module: MTLibuv::Reactor::ClassMethods

Included in:
MTLibuv::Reactor
Defined in:
lib/mt-libuv/reactor.rb

Instance Method Summary collapse

Instance Method Details

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

Build a Ruby MTLibuv reactor from an existing reactor pointer

Returns:



52
53
54
# File 'lib/mt-libuv/reactor.rb', line 52

def create(pointer)
    allocate.tap { |i| i.send(:initialize, pointer) }
end

#current::MTLibuv::Reactor | nil

Checks for the existence of a reactor on the current thread

Returns:



59
60
61
# File 'lib/mt-libuv/reactor.rb', line 59

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

#default::MTLibuv::Reactor

Get default reactor

Returns:



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

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

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

Create new MTLibuv reactor

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mt-libuv/reactor.rb', line 36

def new(&blk)
    memory = ::MTLibuv::Ext::LIBC.malloc(::MTLibuv::Ext.loop_size)
    ::MTLibuv::Ext.loop_init(memory)

    thread = create(memory)
    if block_given?
        ::Thread.new do
            thread.run &blk
        end
    end
    thread
end