Class: PgVersions::Connection
- Inherits:
-
Object
- Object
- PgVersions::Connection
- Defined in:
- lib/pg_versions/pg_versions.rb
Defined Under Namespace
Classes: Subscription
Instance Method Summary collapse
- #bump(*channels) ⇒ Object
- #close ⇒ Object
-
#initialize(connection = nil) ⇒ Connection
constructor
A new instance of Connection.
- #read(*channels) ⇒ Object
- #subscribe(*channels, known: {}) ⇒ Object
Constructor Details
#initialize(connection = nil) ⇒ Connection
Returns a new instance of Connection.
290 291 292 |
# File 'lib/pg_versions/pg_versions.rb', line 290 def initialize(connection=nil) @connection_thread = ConnectionThread.new(connection) end |
Instance Method Details
#bump(*channels) ⇒ Object
298 299 300 |
# File 'lib/pg_versions/pg_versions.rb', line 298 def bump(*channels) @connection_thread.request(:bump, channels) end |
#close ⇒ Object
294 295 296 |
# File 'lib/pg_versions/pg_versions.rb', line 294 def close() @connection_thread.request(:stop) end |
#read(*channels) ⇒ Object
303 304 305 |
# File 'lib/pg_versions/pg_versions.rb', line 303 def read(*channels) @connection_thread.request(:read, channels) end |
#subscribe(*channels, known: {}) ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/pg_versions/pg_versions.rb', line 308 def subscribe(*channels, known: {}) subscription = Subscription.new(@connection_thread) subscription.subscribe([channels].flatten, known: known) if block_given? Thread.handle_interrupt(Object => :never) { begin Thread.handle_interrupt(Object => :immediate) { yield subscription } ensure subscription.drop end } else subscription end end |