Class: Green::Hub

Inherits:
Object
  • Object
show all
Defined in:
lib/green/hub.rb,
lib/green/hub/nio4r.rb,
lib/green/hub/em.rb

Direct Known Subclasses

EM, Nio4r

Defined Under Namespace

Classes: EM, Nio4r

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHub

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

#gObject (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

#runObject



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_hubObject



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

#stopObject



58
59
60
# File 'lib/green/hub.rb', line 58

def stop
  raise "override"
end

#switchObject



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