Class: Green::Hub
- Inherits:
-
Object
- Object
- Green::Hub
- Defined in:
- lib/green/hub.rb,
lib/green/hub/nio4r.rb,
lib/green/hub/em.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#g ⇒ Object
readonly
Returns the value of attribute g.
Instance Method Summary collapse
- #callback(&blk) ⇒ Object
-
#initialize ⇒ Hub
constructor
A new instance of Hub.
- #run ⇒ Object
- #sleep(n) ⇒ Object
- #socket_waiter(socket) ⇒ Object
- #start_hub ⇒ Object
- #stop ⇒ Object
- #switch ⇒ Object
- #timer(n, &blk) ⇒ Object
- #wait(proc = nil, &cancel_clb) ⇒ Object
Constructor Details
#initialize ⇒ Hub
Returns a new instance of Hub.
4 5 6 7 |
# File 'lib/green/hub.rb', line 4 def initialize start_hub end |
Instance Attribute Details
#g ⇒ Object (readonly)
Returns the value of attribute g.
3 4 5 |
# File 'lib/green/hub.rb', line 3 def g @g end |
Instance Method Details
#callback(&blk) ⇒ Object
50 51 52 |
# File 'lib/green/hub.rb', line 50 def callback(&blk) raise "override" end |
#run ⇒ Object
42 43 44 |
# File 'lib/green/hub.rb', line 42 def run raise "override" end |
#sleep(n) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/green/hub.rb', line 35 def sleep(n) g = Green.current t = timer(n) { g.switch } wait { t.green_cancel } t end |
#socket_waiter(socket) ⇒ Object
54 55 56 |
# File 'lib/green/hub.rb', line 54 def socket_waiter(socket) raise "override" end |
#start_hub ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/green/hub.rb', line 9 def start_hub c = Green.current callback { c.switch } @g = Green.new do begin run rescue => e start_hub raise end end g.switch end |
#stop ⇒ Object
58 59 60 |
# File 'lib/green/hub.rb', line 58 def stop raise "override" end |
#switch ⇒ Object
24 25 26 |
# File 'lib/green/hub.rb', line 24 def switch g.switch end |
#timer(n, &blk) ⇒ Object
46 47 48 |
# File 'lib/green/hub.rb', line 46 def timer(n, &blk) raise "override" end |
#wait(proc = nil, &cancel_clb) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/green/hub.rb', line 28 def wait(proc = nil, &cancel_clb) switch rescue => e (proc || cancel_clb).call raise e end |