Class: DNode

Inherits:
Object
  • Object
show all
Defined in:
lib/dnode.rb

Defined Under Namespace

Classes: Listener

Instance Method Summary collapse

Constructor Details

#initialize(obj = {}) ⇒ DNode

Returns a new instance of DNode.



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

def initialize obj={}
    @instance = obj
end

Instance Method Details

#connect(*args, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/dnode.rb', line 30

def connect *args, &block
    params = from_args(*args, &block).merge(:instance => @instance)
    EM.run do EM.connect(params[:host], params[:port]) do |c|
        conn = Conn.new(params.merge :conn => c)
        handle_conn(c, conn)
    end end
end

#listen(*args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/dnode.rb', line 41

def listen *args, &block
    params = from_args(*args, &block).merge(:instance => @instance)
    EM.run do
        EM.start_server(params[:host], params[:port], Listener) do |c|
            conn = Conn.new(params.merge :conn => c)
            handle_conn(c, conn)
        end
    end
end