Class: Coolio::Loop

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#waitingsObject (readonly)

Returns the value of attribute waitings.



109
110
111
# File 'lib/pmux/mros.rb', line 109

def waitings
  @waitings
end

Instance Method Details

#runObject

Raises:

  • (RuntimeError)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/pmux/mros.rb', line 124

def run
  raise RuntimeError, "no watchers for this loop" if @watchers.empty?

  @running = true
  while @running and not @active_watchers.zero?
    run_once
    if @waitings and !@waitings.empty?
      busy_sessions = @waitings.select {|f, s| s.busy?}
      for fiber, ssh in busy_sessions
        @waitings.delete fiber
        fiber.resume
      end
    end
  end
  @running = false
end

#set_timer(interval, repeating = false, &block) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/pmux/mros.rb', line 141

def set_timer(interval, repeating=false, &block)
  timer = TimerWatcher.new interval, repeating
  timer.on_timer {
    block.call
    timer.detach unless repeating
  }
  timer.attach self
end

#start_ssh(*args, &block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/pmux/mros.rb', line 110

def start_ssh *args, &block
  @waitings ||= {}
  fiber = Fiber.new {
    begin
      ssh = Net::SSH.start *args
      ssh.coolio_loop = self
      block.call ssh
    rescue => e
      block.call e
    end
  }
  fiber.resume
end