Module: PG::EM::Client::ConnectWatcher
- Defined in:
- lib/pg/em.rb
Instance Method Summary collapse
- #initialize(client, deferrable, poll_method) ⇒ Object
- #notify_readable ⇒ Object
- #notify_writable ⇒ Object
- #poll_connection_and_check ⇒ Object
- #reconnecting? ⇒ Boolean
Instance Method Details
#initialize(client, deferrable, poll_method) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/pg/em.rb', line 221 def initialize(client, deferrable, poll_method) @client = client @deferrable = deferrable @poll_method = :"#{poll_method}_poll" if (timeout = client.connect_timeout) > 0 @timer = ::EM::Timer.new(timeout) do begin detach @deferrable.protect do raise PG::Error, "timeout expired (async)" end ensure @client.finish unless reconnecting? end end end end |
#notify_readable ⇒ Object
247 248 249 |
# File 'lib/pg/em.rb', line 247 def notify_readable poll_connection_and_check end |
#notify_writable ⇒ Object
243 244 245 |
# File 'lib/pg/em.rb', line 243 def notify_writable poll_connection_and_check end |
#poll_connection_and_check ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/pg/em.rb', line 251 def poll_connection_and_check case @client.__send__(@poll_method) when PG::PGRES_POLLING_READING self.notify_readable = true self.notify_writable = false when PG::PGRES_POLLING_WRITING self.notify_writable = true self.notify_readable = false when PG::PGRES_POLLING_OK, PG::PGRES_POLLING_FAILED @timer.cancel if @timer detach @deferrable.protect_and_succeed do unless @client.status == PG::CONNECTION_OK begin raise PG::Error, @client. ensure @client.finish unless reconnecting? end end # mimic blocking connect behavior @client.set_default_encoding unless reconnecting? @client end end end |
#reconnecting? ⇒ Boolean
239 240 241 |
# File 'lib/pg/em.rb', line 239 def reconnecting? @poll_method == :reset_poll end |