Class: Green::Hub::EM

Inherits:
Green::Hub show all
Defined in:
lib/green/hub/em.rb

Defined Under Namespace

Classes: SocketWaiter

Instance Attribute Summary

Attributes inherited from Green::Hub

#g

Instance Method Summary collapse

Methods inherited from Green::Hub

#initialize, #sleep, #start_hub, #switch, #wait

Constructor Details

This class inherits a constructor from Green::Hub

Instance Method Details

#callback(cb = nil, &blk) ⇒ Object



72
73
74
# File 'lib/green/hub/em.rb', line 72

def callback(cb=nil, &blk)
  ::EM.next_tick(cb || blk)
end

#runObject

если мы запускаем приложение внутри thin или rainbows с EM, то значит мы уже внутри EM-реактора, а hub должен переключиться в main тред.



58
59
60
61
62
63
64
65
66
# File 'lib/green/hub/em.rb', line 58

def run
  if ::EM.reactor_running?
    loop do
      Green.main.switch
    end
  else
    ::EM.run
  end
end

#socket_waiter(socket) ⇒ Object



76
77
78
# File 'lib/green/hub/em.rb', line 76

def socket_waiter(socket)
  SocketWaiter.new socket
end

#stopObject



80
81
82
# File 'lib/green/hub/em.rb', line 80

def stop
  EM.stop
end

#timer(n, &blk) ⇒ Object



68
69
70
# File 'lib/green/hub/em.rb', line 68

def timer(n, &blk)
  ::EM::Timer.new(n, &blk)
end